Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用jquery从代码隐藏中将ASP.NET中的文本框清除为0_C#_Jquery_Asp.net - Fatal编程技术网

C# 使用jquery从代码隐藏中将ASP.NET中的文本框清除为0

C# 使用jquery从代码隐藏中将ASP.NET中的文本框清除为0,c#,jquery,asp.net,C#,Jquery,Asp.net,我想将divData中的所有文本框清除为0。如果想清除页面中的所有文本框,我使用了下面的第一行代码。但我只想弄清楚舱内的东西。我是不是遗漏了什么 protected void ResetTextboxes() { //This Works fine but it clears all the textboxes on the page // string jquery = "$('input[type=text]').val('0');"; //C

我想将divData中的所有文本框清除为0。如果想清除页面中的所有文本框,我使用了下面的第一行代码。但我只想弄清楚舱内的东西。我是不是遗漏了什么

protected void ResetTextboxes()
{
       //This Works fine but it clears all the textboxes on the page
       // string jquery = "$('input[type=text]').val('0');"; 

        //Can't get this to work. This does not clear textboxes in divData only
        string jquery = "$('#divData input').val('0');";

        ClientScript.RegisterStartupScript(typeof(Page), "a key",
        "<script type=\"text/javascript\">" + jquery + "</script>");


  }  
受保护的无效重置文本框()
{
//这很好,但它会清除页面上的所有文本框
//字符串jquery=“$('input[type=text]').val('0');”;

//无法执行此操作。这不会仅清除divData中的文本框 字符串jquery=“$('#divData input').val('0');”; RegisterStartupScript(typeof(Page),“一个键”, “+jquery+”); }
我让它工作了。由于页面附加到母版页,我必须附加ContentPLaceHolder ID加上子页面中使用的Div的ID

 protected void ResetTextboxes()
 {

        string jquery = "$('#MainContent_divData input[type=text]').val('0');";

        ClientScript.RegisterStartupScript(typeof(Page), "a key",
        "<script type=\"text/javascript\">" + jquery + "</script>");          
  }    
受保护的无效重置文本框()
{
字符串jquery=“$('#MainContent_divData input[type=text]”)。val('0');
RegisterStartupScript(typeof(Page),“一个键”,
“+jquery+”);
}    

“无法使其工作。这不会仅清除divData中的文本框…”为什么不工作?它会做什么呢?它什么也不做,它不会清除文本框您确定页面上有id为“divData”的元素吗?看起来您使用的webforms可能会稍微损坏您的ID。我需要将母版页ContentPlaceHolder ID附加到div。这是一个非常脆弱的解决方案,divData控件应该有一个ClientID属性,您可以使用该属性获取将显示在页面上的ID。您可以将它与:
string.format($('{0}input[type=text]').val('0');”,divData.ClientID)
一起使用。这样做可以防止它在重命名或移动时损坏。