asp.net the following button click to disable the implementation code

Source: Internet
Author: User
Tags copy implement min net xmlns
first, let the button after clicking on the script to disable it:
Copy CodeThe code is as follows:
<%@ Page language= "C #" autoeventwireup= "true" codebehind= "WebForm1.aspx.cs" inherits= "Disablebutton.webform1"% >
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title></title>
<script type= "Text/javascript" src= "Scripts/jquery-1.4.1.min.js" ></script>
<script type= "Text/javascript" >
function Enablebutton (flag) {
$ ("#btnTest"). attr ("Disabled", flag?) "": "Disabled");
}
$ (document). Ready (
function () {
$ ("#btnTest"). Click (
function () {
Enablebutton (FALSE),//Click to disable
}
);
}
);
</script>
<body>
<form id= "Form1" runat= "Server" >
<div>
<asp:button id= "btntest" text= "After clicking Disable" runat= "Server"/>
</div>
</form>
</body>

But the fact is sadly telling us that this is not going to work: the page will not be sent back at all. So, we have to look for other ways.
Copy CodeThe code is as follows:
<%@ Page language= "C #" autoeventwireup= "true" codebehind= "WebForm1.aspx.cs" inherits= "Disablebutton.webform1"% >
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title></title>
<script type= "Text/javascript" src= "Scripts/jquery-1.4.1.min.js" ></script>
<script type= "Text/javascript" >
function Enablebutton (flag) {
$ ("#btnTest"). attr ("Disabled", flag?) "": "Disabled");
}
$ (document). Ready (
function () {
$ ("#btnTest"). Click (
function () {
Enablebutton (FALSE);
$ ("#btnTest2"). Click ()//disable itself and invoke the Click event of the button that actually triggers the postback
}
);
}
);
</script>
<body>
<form id= "Form1" runat= "Server" >
<div>
<input type= "button" value= "After clicking Disable" id= "btntest"/>
<asp:button id= "BtnTest2" text= "After clicking Disable" runat= "server" style= "Display:none"/>
</div>
</form>
</body>

So our purpose is achieved. Finally, we introduce a way: three, using settimeout to realize
Copy CodeThe code is as follows:
<%@ Page language= "C #" autoeventwireup= "true" codebehind= "WebForm1.aspx.cs" inherits= "Disablebutton.webform1"% >
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title></title>
<script type= "Text/javascript" src= "Scripts/jquery-1.4.1.min.js" ></script>
<script type= "Text/javascript" >
function Enablebutton (flag) {
$ ("#btnTest"). attr ("Disabled", flag?) "": "Disabled");
}
$ (document). Ready (
function () {
$ ("#btnTest"). Click (
function () {
settimeout (function () {
Enablebutton (FALSE);
},
50);
}
);
}
);
</script>
<body>
<form id= "Form1" runat= "Server" >
<div>
<asp:button id= "btntest" text= "After clicking Disable" runat= "Server"/>
</div>
</form>
</body>

This allows us to implement the requirements without introducing a secondary control.
Note: In order to better observe the effect of the experiment, you can sleep a few seconds in the Click Time Processing function of the button.
Of course, you can use jquery's unbind and bind functions to implement the Click event Removal or add operation.

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.