Home All Groups Group Topic Archive Search About

Disable a button in Javascript disables server-side code

Author
4 May 2006 10:18 PM
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?

Author
5 May 2006 2:14 AM
Bob Lehmann
Disabled form elements are not included in the post data. You will have to
re-enable them onsubmit.

Bob Lehmann

Show quoteHide quote
"David Davis" <DavidDa***@discussions.microsoft.com> wrote in message
news:AF16A284-0287-4635-9DCA-0EFB6FFF7F0D@microsoft.com...
> 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?
>
>
Author
5 May 2006 1:48 PM
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.

Show quoteHide quote
"David Davis" wrote:

> 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?
>
>
Author
9 May 2006 10:30 PM
Chineme Nnamdi
When you disable an asp button with client script it prevent the server side on click event from firing. What you need to do is to fire the onclick event of the button first before disabling the button. (view snippet below)

function DisableButton()
{
       <%=Page.GetPostBackEventReference(ImageButton1 as Control)%>
       document.getElementById('ImageButton1').disabled = true;
}

Chineme Nnamdi