Assign a value to the server control

Source: Internet
Author: User

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 ....

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.