Solved

Disable Button in AJAX Panel

Posted on 2010-08-30
5
685 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 6

Expert Comment

by:thaytu888888
ID: 33560187
- <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
ID: 33562499
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
ID: 33562566
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
ID: 33563950
- Here is the solution:
function disableButton(btn) {
            if (btn) {
                __doPostBack(btn.id, "");
                btn.disabled = true;
            }
        }
0
 

Author Comment

by:Carleton_H
ID: 33564218
Thanks, worked like a charm!
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

730 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