Move from my Netease blog .....
A server control button is added to Itemtemplate in ListView. After rendering by the server. It is difficult to obtain the ID of the button. Therefore, ID data is bound to the button in ItemDataBound.
Btn. attributes ["MyId"] = btn. clientID; btn. attributes ["onclick"] = "check (" + slid + ", this);"; // an onclick event is bound. this can also be used as the ID of the current btn.
Front-end javascript.
I wrote ajax to get the button ID from the anonymous function. Defined in function check (slid, src)
var myid = $(src).attr("MyId");
Then, the anonymous function in post finds that the button status cannot be changed ..
$ ("#" + Myid). val ("checked in"); $ ("#" + myid). attr ("disabled", "disabled ");
After trying, we found that the value of the button can be obtained. But it cannot be changed.
$ ("#" + Myid). val ("checked in"); $ ("#" + myid). attr ("disabled", "disabled ");
Alert ("yes"); // Add this sentence and test it. After this prompt is displayed, the button status changes. However, the page is being post. After the post is complete, the button status is restored.
So. Solving the problem of button without post is the right path. Because it is a server control. Therefore, every Control performs _ dopostBack;
Add UseSubmitBehavior = "false" to the button ";<Asp: Button runat = "server" UseSubmitBehavior = "false" ID = "SignUp" Text = "sign in"/>
The test shows that the post operation is still performed. You must disable _ dopostBack when checking the information. Therefore, add the check method at the end of javascript.
_dopostBack(myid,"");
_ DoPostBack has two parameters. eventTarget indicates the ID of the control that will trigger the page PostBack. The eventArgument parameter provides additional parameters when the page PostBack event is triggered.
So far. Modify the server control. Khan. This small problem has been around for two or three days ....