Solved

Disable Button in AJAX Panel

Posted on 2010-08-30
5
676 Views
Last Modified: 2012-05-10
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?
0
Comment
Question by:Carleton_H
  • 3
  • 2
5 Comments
 
LVL 6

Expert Comment

by:thaytu888888
Comment Utility
- <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

0
 

Author Comment

by:Carleton_H
Comment Utility
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?
0
 

Author Comment

by:Carleton_H
Comment Utility
Is it possible to execute the btn_Step42_UploadRules_Click code-behind from the Javascript function you supplied?
0
 
LVL 6

Accepted Solution

by:
thaytu888888 earned 500 total points
Comment Utility
- Here is the solution:
function disableButton(btn) {
            if (btn) {
                __doPostBack(btn.id, "");
                btn.disabled = true;
            }
        }
0
 

Author Comment

by:Carleton_H
Comment Utility
Thanks, worked like a charm!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now