c# - Disable buttons after click until post back of ascx control using javascript -
the page works expected, disables buttons , shows loading indicator onclick event never called. relatively inexperienced javascript , cannot seem find answer why doesn't work.
i expect once disable() method occurs , returns true call onclick method, cause post , automatically re-enable buttons.
perhaps going @ wrong, appreciate help.
<%@ register tagprefix="componentart" namespace="componentart.web.ui" assembly="componentart.web.ui" %> <%@ control language="c#" inherits="mycontrol" codebehind="thiscontrol.ascx.cs"%> <div class="form" style="width: 100%"> <img id="imgloading" src="images/gridimages/spinner.gif" style="display:none" alt="loading..." /> <ol> <li> <asp:button id="firstbutton" cssclass="btn" runat="server" text="first press me" onclick="first_click" onclientclick="this.value='please wait...'; needtoconfirm=false; return disable(); "/> <span> <asp:button id="secondbutton" cssclass="btn" runat="server" text="second press me" onclick="second_click" onclientclick="this.value='please wait...'; needtoconfirm=false; return disable(); "/> </span> </li> </ol> <script type="text/javascript"> function disable() { document.getelementbyid('<%=firstbutton.clientid %>').disabled = true; document.getelementbyid('<%=secondbutton.clientid %>').disabled = true; settimeout('updateimg()', 0); return true; } function updateimg() { $('#imgloading').show(); var img = document.getelementbyid('imgloading'); img.src = 'images/gridimages/spinner.gif'; } </script> </div>
found answer here.
added "usesubmitbehavior = false", , voila, onclick event called.
apparently asp respects disabling of button , causes event fire fail.
Comments
Post a Comment