Disabled button does not send back to UpdatePanel

I have a button inside the UpdatePanel on my ASP.NET page. Here is my UpdatePanel

 <asp:UpdatePanel ID="UpdateToolbar" runat="server" UpdateMode="Conditional"> <ContentTemplate> <table> <tr> <td> <div id="divPDFBtn"> <asp:Button ID="btnPrint" runat="server" OnClick="btnPrint_Click" ToolTip="Click to export report to PDF" Width="100px" Text="Print to PDF" OnClientClick="if(PDFClick()) {return true;} else {alert('2');}" /> </div> </td> </tr> </table> </ContentTemplate> <Triggers> <asp:PostBackTrigger ControlID="btnPrint" /> </Triggers> </asp:UpdatePanel> 

When I try to disable the OnClientClick button, it does not PostBack

Here is an example of my PDFClick() function

 // Works (does post back and code behind executes)) <script type="text/javascript"> function PDFClick() { document.getElementById("btnPrint").value = "Working..."; return true; }; </script> // Doesn't work (JS executes, but code behind didn't execute) <script type="text/javascript"> function PDFClick() { document.getElementById("btnPrint").value = "Working..."; document.getElementById("btnPrint").disabled = true; return true; }; </script> 

This is my code. I need to do something on the back and open a new window after this:

 protected void btnPrint_Click(object sender, EventArgs e) { Response.Write("<script>"); Response.Write(String.Format("window.open('{0}','_blank')", ResolveUrl("PrintPage.aspx"))); Response.Write("</script>"); } 

Please advise how I can turn off my button and get the code behind.

Thanks!

0
javascript c # button updatepanel
source share
2 answers

You can disable the button asynchronously with setTimeout :

 <script type="text/javascript"> function PDFClick(btnPrint) { btnPrint.value = "Working..."; setTimeout(function() { btnPrint.disabled = true; }, 10); return true; }; </script> 

The call to document.getElementById can be removed from PDFClick by passing a link to the button element with the this in OnClientClick :

 OnClientClick="if (PDFClick(this)) { return true; } else { alert('2'); }" 
+2
source share

Add ClientIDMode="Static" to the button

 <asp:Button ID="btnPrint" runat="server" OnClick="btnPrint_Click" ToolTip="Click to export report to PDF" Width="100px" Text="Print to PDF" OnClientClick="if(PDFClick()) {return true;} else {alert('2');}" ClientIDMode="Static" /> 
0
source share

All Articles