Set the disabled attribute of the button in Js.

Source: Internet
Author: User

On the. NET page, you must have a button. Click it to set the disabled attribute of this button and trigger server events. The Code is as follows:

HTML:

<Form ID = "form1" runat = "server">
<Asp: button id = "button1" runat = "server" onclick = "button#click" text = "button" onclientclick = "This. Disabled = true; return true;"/>
</Form>

 

C #

Protected void button#click (Object sender, eventargs E)
{}

 

But the problem is that he only triggered the client event, and the server event was not executed at all.

I checked the information. After usesubmitbehavior = "false" is added, client events can be triggered first, the disabled attribute can be set, and server events can be executed.

However, after the server event is executed, the property disabled is changed to enabled again.

Finally, to meet the requirements, simply set enabled on the server side. Then, the client can use a required item to trigger and then clear the property disabled of the button.

The complete code is as follows:

JS Code:

Function display1 ()
{
Document. getelementbyid ("<% = button1.clientid %>"). removeattribute ("disabled ");
}

HTML code:

<Form ID = "form1" runat = "server">
<Input type = "text" runat = "server" onchange = "display1 ()"/>
<Asp: button id = "button1" runat = "server" onclick = "button#click" text = "button"/>
</Form>

C # code:

Protected void button#click (Object sender, eventargs E)
{
This. button1.enabled = false;
}

 

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.