Thoughts on button resetting-jquery & Ajax

Source: Internet
Author: User

Problem:

Questions about resetting

There is a type = "reset" button in HTML, which is used to indicate the status or value of the page element.

However, in the following cases, its function seems to be ineffective.

Scenario technology: Ajax & jquery & type = "reset"

Page:

<Asp: textbox id = "txtbox" runat = "server"> </ASP: textbox>

<Input id = "reset" type = "reset" class = "signedbtn"/>

Script:

<SCRIPT type = "text/JavaScript" Language = "JavaScript">

$ ("# RESET"). Click (function (){

// Reset textbox
VaR entryarr = [txtbox, txtbox1, txtbox2];
$. Each (entryarr, function (){
This. Val ("");
});

});

</SCRIPT>

AboveCodeIs the code written by the textbox.

When we add Ajax: updatepanel to the page

Page

<Ajax: updatepanel id = "up" runat = "server" updatemode = "Conditional">
<Contenttemplate>

<Asp: textbox id = "txtbox" runat = "server"> </ASP: textbox>

<Input id = "reset" type = "reset" class = "signedbtn"/>

</Contenttemplate>
</Ajax: updatepanel>

Script:

<SCRIPT type = "text/JavaScript" Language = "JavaScript">

$ ("# RESET"). Click (function (){

// Reset textbox
VaR entryarr = [txtbox, txtbox1, txtbox2];
$. Each (entryarr, function (){
This. Val ("");
});

});

</SCRIPT>

The above blue code block is basically valid only for the first execution. However, when updatepanel occurs PostBack or something, clicking the reset button again is invalid.

For the main reasons, refer:

Http://www.cnblogs.com/blodfox777/archive/2008/12/08/1347805.html

Solution:

<SCRIPT type = "text/JavaScript" Language = "JavaScript">
Function pageload (sender, argS ){

$ ("# RESET"). Click (function (){

// Reset textbox
VaR entryarr = [txtbox, txtbox1, txtbox2];
$. Each (entryarr, function (){
This. Val ("");
});

});

}

</SCRIPT>

But for the above cases,The page reset function is still invalid.

See the following

Figure 1: Click Reset

Figure 2: click "OK"

Why? Why?

Why is the value in textbox written back to textbox?

Cause: I may have analyzed the problem of type = "reset" and updatepanel. Why is it unclear?

Solution: use regular buttons

Page

<Ajax: updatepanel id = "up" runat = "server" updatemode = "Conditional">
<Contenttemplate>

<Asp: textbox id = "txtbox" runat = "server"> </ASP: textbox>

<Asp: button id = "btncancel" runat = "server" text = "reset" cssclass = "signedbtn"/>

<% -- <Input id = "reset" type = "reset" class = "signedbtn"/> -- %>

</Contenttemplate>
</Ajax: updatepanel>

Script:

<SCRIPT type = "text/JavaScript" Language = "JavaScript">

Function pageload (sender, argS ){

$ ("# <% = Btncancel. clientid %>"). Click (function (){

// Reset textbox
VaR entryarr = [txtbox, txtbox1, txtbox2];
$. Each (entryarr, function (){
This. Val ("");
});

});

}

</SCRIPT>

 

reference: http://forums.asp.net/p/1448643/3300979.aspx

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.