Bryuk Bryuk - 1 year ago 128
Javascript Question

Disabled button doesn't submit postback in UpdatePanel

I have a button inside

on my
Page. Here's my

<asp:UpdatePanel ID="UpdateToolbar" runat="server" UpdateMode="Conditional">
<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');}" />
<asp:PostBackTrigger ControlID="btnPrint" />

When I'm trying to disable button
it doesn't do

Here's example of my

// Works (does post back and code behind executes))
<script type="text/javascript">
function PDFClick() {
document.getElementById("btnPrint").value = "Working...";
return true;

// 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;

This is my code behind. I need to do some stuff on the back and open new window after it's done:

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

Please advise how I can disable my button and reach code behind.


Answer Source

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;

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

OnClientClick="if (PDFClick(this)) { return true; } else { alert('2'); }"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download