简体   繁体   中英

Client side and server side events not firing simultaneously

I have a asp.net button control. My requirement is such that upon clicking the button, it should be disabled and fire a server side event simultaneously. I am disabling the button by

onclientclick = "this.disabled = true;"

and calling the server side method by

onclick = "someserversidemethod"

But the thing is that button is getting disabled and not firing the server side event. I want both client side and server side events to fire simultaneously. Please help.

Keep what you have and also set the property UseSubmitBehavior="false" . This will force the button to use the asp.net postback mechanism, rather than the inbuilt browser mechanism.

See here for more details

EDIT

Browsers as standard will always submit a form when you click on a <input type="submit"> control (which is what is rendered to the HTML when you use a <asp:Button> ). ASP.NET uses this feature to initiate the postback to the server.

The problem you have is that if the button is disabled (like you are doing in your javascript) then the browser will not submit the form (ie the postback will not happen).

By using the attribute UseSubmitBehavior="false" you are telling ASP.NET to ignore the fact that browsers can do the submit themselves, and instead the button should use the JavaScript postback methods provided by ASP.NET (the same methods that are used on AutoPostback="true" for things like <asp:Checkbox> etc).

The javascript postback ignores the fact that you have just set the control as disabled,meaning the control will be disabled on screen but the postback will still happen.

I hope that makes sense

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM