简体   繁体   中英

Clear textboxes to 0 in ASP.NET using jquery from code behind

I want to clear all the textboxes to 0 that are in my divData. If want to clear all the textboxes in the page I used the first line of code below. But I only want to clear what is inside the div. Am I missing something ?

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>");


  }  

I got it working. Since the page is attached to a MasterPage, I had to append the ContentPLaceHolder ID plus the ID of the Div used in the child page.

 protected void ResetTextboxes()
 {

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM