Question

This is killing me has to be something simple I am overlookng. 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 = ture; never turned the button on.

Still puzzled

Was it helpful?

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

OTHER TIPS

Nope, You use HTML controls when you don't need the control to run on the server-side, not ASP.NET server controls.

i.e.

< input type="button" / >

instead of

< asp:Button ID="btn" runat="server" / >
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top