I've got a page with a save button that's to be enabled only after edits have been made (otherwise what are you saving, right?). So right now it's an asp:button, so I disable it with Enabled="false".

<asp:Button runat="server" ID="cmdSavePrimaryClientEdits" Text="Save" 
onclick="cmdSavePrimaryClientEdits_Click"
OnClientClick="checkCboMasks();"
Enabled="false" />


Bad news. I couldn't for the life of me figure out why my OnClientClick function call wasn't in the html. Finally, a StackOverflow comment gave me the answer...

asp.net - OnClientClick not working - Stack Overflow:


Another possibility: if the button is disabeld when the page is rendered, then the OnClientClick event is NOT written to HTML. Is your button disabled when the page is rendered? โ€“ AASoft Sep 17 '09 at 22:35


Hey, Ballmer, WHAT THE HECK GOOD IS IT TO REMOVE THE FREAKIN' ONCLIENTCLICK IF THE BUTTON'S DISABLED? IT'S NOT LIKE IT'LL ACCIDENTALLY GET CALLED, OKAY?!!!

ARGH. What a pain. I can now either use jQuery to attach my click event to the button after it's rendered OR I can remove the Enabled attribute and use jQuery to disable it once the page is done loading. What a freakin' kludge o' freakin' rama.

So here's the jQuery fix:
$('#<%=cmdSavePrimaryClientEdits.ClientID %>').attr('disabled', 'disabled');

/sigh

Labels: , ,