Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7955869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:49:07+00:00 2026-06-04T03:49:07+00:00

I have an <asp:Button ID=btnExport> control inside of an UpdatePanel. When that button is

  • 0

I have an <asp:Button ID="btnExport"> control inside of an UpdatePanel. When that button is clicked, I’d like it to immediately execute a Javascript function (it’s a polling function that will run continuously while the UpdatePanel is doing its postback). How can I do this?

I’ve tried this:

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_pageLoaded(pageLoaded);
function pageLoaded(sender, args) {
    $(".btnExport").click(function (e) {
        timer = window.setInterval(pollStatus, 1000);//        
    });
}

That works, but then it doesn’t execute the btnExport event handler. Everything I try either executes the event handler and not the polling function or vice-versa. What I’m really looking for is a way to do this:

1) Click on the Export button.

2) Set a timer to do a polling event (javascript function) every second.

3) Execute the event handler for the Export button.

4) Once the postback is done, clear the timer.

Anyone have any suggestions as to the best way to accomplish this?

Here’s some sample code. This is from a small sample application I wrote just to illustrate the point, my actual app is a bit too complex to post here.

DEFAULT.ASPX

<asp:ScriptManager runat="server" ID="ScriptManager1"></asp:ScriptManager>

    <asp:UpdatePanel runat="server" ID="UpdatePanel1">
        <ContentTemplate>
            <asp:Button runat="server" ID="btnExport" Text="Begin Export" OnClick="btnExport_Click" ClientIDMode="Static" /><div id="message"></div>
        </ContentTemplate>
    </asp:UpdatePanel>

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript" language="javascript">
        var timer;

        function pollStatus() {
            $.ajax({
                type: "POST",
                url: "<%= Page.ResolveUrl("~/Default.aspx/PollStatus") %>",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    $("#message").html(response.d);
                }
            });   
        }

        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_pageLoaded(pageLoaded);
        function pageLoaded(sender, args) {
            $("#btnExport").click(function (e) {
                timer = window.setInterval(pollStatus, 50);
            });
        }
</script>

DEFAULT.ASPX.CS

protected void btnExport_Click(object sender, EventArgs e)
        {
            for (int i = 1; i <= 10000000; i++ )
            {
                Session["PollStatus"] = i;
            }
        }

        [WebMethod]
        public static string PollStatus()
        {
            return HttpContext.Current.Session["PollStatus"] != null ? HttpContext.Current.Session["PollStatus"].ToString() : "No result";
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T03:49:09+00:00Added an answer on June 4, 2026 at 3:49 am

    I do not see a css class specified here:

    <asp:Button ID="btnExport">
    

    However, your selector is trying to get the object(s) by class:

    $(".btnExport")
    

    So, you should either set the CssClass property for your button or change the selector.

    UPD:
    This code works for me just fine (this is an example, It requires some polishing before prod. usage)

    <form id="form1" runat="server">
    
        <asp:ScriptManager runat="server" ID="scmMain"></asp:ScriptManager>
    
        <asp:UpdatePanel runat="server" ID="pnlMain">
            <ContentTemplate>
                <asp:Button Text="Test" ID="btnTest" CssClass="btnTest" runat="server" OnClick="btnTest_OnClick"/>
            </ContentTemplate>
        </asp:UpdatePanel>
    
        <script type="text/javascript">
            var prm = Sys.WebForms.PageRequestManager.getInstance();
            prm.add_pageLoaded(pageLoaded);
            var timer;
            function pageLoaded(sender, args) {
                if (prm.get_isInAsyncPostBack()) {
                    window.clearInterval(timer);
                }
                else {
                    $(".btnTest").click(function (e) {
                        timer = window.setInterval(pollStatus, 1000);
                    });
                }
            }
    
            function pollStatus() {
                alert('Test');
            }
    
        </script>
    
    </form>
    

    The button’s btnTest_OnClick server-side event handler just does this:

    Thread.Sleep(5000);
    

    You should see “Test” alerts until the server provides a response back to the client.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an asp.net button wrapped inside of an UpdatePanel, and when clicked it
I have an ASP.NET button. When the button is clicked, I'd like a modal
I have a disabled asp.Button, which I enable later with JavaScript. Like this <asp:Button
I have an ASP button that lookts like this: <asp:Button ID=btnReset runat=server OnClientClick =
i have an asp server button that when clicked should preform some server side
I have an ASP button, when it is clicked it calls a function which
I have a asp:UpdatePanel with a asp:Button and a asp:TextBox : <asp:UpdatePanel ID=UpdatePanel1 runat=server>
i have asp button like this: <asp:Button ID=ImportToDB runat=server OnClick=ImportToDB_Click /> And i need
I have a button on an ASP.net page. <asp:Button Text=<%$Resources: WebResources, Export %> ID=BtnExport
i have asp text box and button control. <asp:TextBox ID=txtFName runat=server CssClass=sfInputbox></asp:TextBox> <asp:Button runat=Server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.