Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Disable Button in AJAX Panel

Posted on 2010-08-30
5
Medium Priority
?
697 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…

721 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