Disable a button in Javascript disables server-side code

D

David Davis

I have a webform with an ImageButton on it. I have assigned an
OnClientScript that calls a javascript function that disables the button like
this:

<script language="javascript">
function DisableButton() {
document.getElementById("ImageButton1").disabled = true;
}
</script>

I have code-behind in the ImageButton1_Click sub that I want to process, but
that code never runs if the OnClientScript disables the button.

Is there a way to disable a button and run code-behind for it?
 
B

Bob Lehmann

Disabled form elements are not included in the post data. You will have to
re-enable them onsubmit.

Bob Lehmann
 
Y

yoga weazel

Sounds more like you want the button disabled after the postback. If this is
what you want you could remove your OnClientClick event handler and if you
Page_Load
event handler if Page.IsPostBack then this.btnImage.Enabled = false;
So when the page renders after processing the click event the button will be
disabled.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top