[SOLVED] asp Button Not firing JavaScript client side

Issue

This is killing me has to be something simple I am overlooking. I am trying to fire off a simple JavaScript function from the click of an ASP button. My button looks like this:

<asp:Button ID="btnFinalize" runat="server" Enabled="False" OnClientClick="finalizeClick(); return false;" Text="Finalize Selection" />

I do enable it based on some other client logic, once enabled I click it but nothing happens.

I have a break point inside the JS function finalizeClick() it never gets there.

So I tried a regular HTML button and it calls the function just fine and performs as expected. It looks like:

<input  type="button" id="btnFinalizeNotASP" value="button" onclick="finalizeClick();"/>

Going crazy, please help.

EDIT More info. Has to be something with Enabled="False". If I take that out of the ASP tag it works. I want to start with the button disabled and enable it on other events client side I do that in another JavaScript event where I set:

finalizeButton.disabled = false;

Not sure why but finalizeButton.enabled = true; never turned the button on.

Still puzzled,

Solution

I figured out something that works, but I don’t really like it. Would like to know from others why and if there is a better solution.

If I leave the:

Enabled="False"

out of my ASP tag and put

var btnfinalize = document.getElementById("<%=btnFinalize.ClientID %>");
btnfinalize.disabled = true;

in the javascript of my page the ASP button is enabled during design, disabled when the page loads and properly fires the javascrip function I want when later enabled (really disabled=false ) and clicked

Answered By – RichP

Answer Checked By – Robin (BugsFixing Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *