Link to home
Start Free TrialLog in
Avatar of Carleton_H
Carleton_H

asked on

Disable Button in AJAX Panel

I have the following button that I would like to disable when it is clicked:
<asp:UpdatePanel id="uPnlC_Step42_UploadRules" runat="server">
<contenttemplate>
    <asp:Button ID="btn_Step42_UploadRules" runat="server" Text="Upload" onclick="btn_Step42_UploadRules_Click" />
</contenttemplate>
<triggers>
        <asp:PostBackTrigger ControlID="btn_Step42_UploadRules" />                
</triggers>
</asp:UpdatePanel> 

Open in new window


I'm able to disable all other buttons in AJAX panels with the below script.  However, for the button in the code above, it doesn't work (I assume because of the use of the trigger?)  This button controls a fileupload control which is why I require a postback.  This is the code I use to disable other AJAX buttons (works for all buttons except the one shown above):

<script language="javascript" type="text/javascript">
    var Page;
    var postBackElement;
    function pageLoad() {
        Page = Sys.WebForms.PageRequestManager.getInstance();
        Page.add_beginRequest(OnBeginRequest);
        Page.add_endRequest(endRequest);
    }

    function OnBeginRequest(sender, args) {
        postBackElement = args.get_postBackElement();
        postBackElement.disabled = true;
    }

    function endRequest(sender, args) {
        postBackElement.disabled = false;
    }  
</script>

Open in new window


Any idea how to make my button disable immediately when clicked?
Avatar of thaytu888888
thaytu888888
Flag of Viet Nam image

- <asp:PostBackTrigger ControlID="btn_Step42_UploadRules" /> this make the Upload button cause a full post back to the server, so the script pageLoad() which call OnBeginRequest and endRequest will never fired. You just need to add a small javascript to disable Upload button when clicked.
<asp:Button ID="btn_Step42_UploadRules" runat="server" Text="Upload" onclick="btn_Step42_UploadRules_Click" OnClientClick="disableButton(this);" />

//Javascripts
function disableButton(btn)
    {
        if(btn)
        {
            btn.disabled = true;
        }
    }

Open in new window

Avatar of Carleton_H
Carleton_H

ASKER

I played around with your solution.  It works great at disabling the button, but unfortunately, the onclick="btn_Step42_UploadRules_Click" isn't getting fired when I have the OnClientClick="disableButton(this);" in there as well.  Any ideas?
Is it possible to execute the btn_Step42_UploadRules_Click code-behind from the Javascript function you supplied?
ASKER CERTIFIED SOLUTION
Avatar of thaytu888888
thaytu888888
Flag of Viet Nam image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, worked like a charm!