Solved

Ajax Timer in update panel causing 502 errors

Posted on 2010-08-27
3
1,107 Views
Last Modified: 2012-05-10
Hi. We have an ajax timer in an asp.net master page that triggers a partial page post back. The timer fires every 10 seconds.

I’m getting 502 errors in IE6 and firefox (not IE8) if the timer is firing at the same times as a full postback is happening – ie the user has clicked a button.
Obviously this is because the ajax call is trying to modify a page that no longer exists (as it’s mid postback).

Is there a way to detect when the timer triggers if a postback has been initiated? I know the simple solution is to turn the timer off when a full postback button is clicked before executing the code (I assume this would work), but as this is in a master page it’ll be a big job to go through all the pages that use this master page.
Any ideas?

The asp.net application is on an intranet, hence using a timer with a 10 second interval.
IE8 handles the fact that the page has changed happily and never gives the error. I can replicate the behaviour in IE6, firefox and chrome.
0
Comment
Question by:PatrickK_W
3 Comments
 
LVL 5

Accepted Solution

by:
sindhuxyz earned 250 total points
ID: 33548691
>>Is there a way to detect when the timer triggers if a postback has been initiated?

if (Page.IsPostBack)

        {

            // get a reference to ScriptManager and check if we have a partial postback

            if (ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack)

            {

                // partial (asynchronous) postback occured

                // insert Ajax custom logic here

            }

            else

            {

                // regular full page postback occured

                // custom logic accordingly                

            }

        }
0
 
LVL 21

Assisted Solution

by:silemone
silemone earned 250 total points
ID: 33562334
or you can see which object is triggering the postback:
You can also cancel postbacks depending on ID, or cause a button click at the end of Postback...

This is javascript, similarly using PageRequestManager...has more control...more options
//goes right after your <form..> tag

 <asp:ToolkitScriptManager ID='tsm' runat='server' EnablePageMethods="true" ></asp:ToolkitScriptManager>

<script type="text/javascript" language="javascript">

        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);

        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

        var elem;

       

        function BeginRequestHandler(sender, args) {

            elem = args.get_postBackElement();

            if (elem.id.toLowerCase() == "fillWithElementIDYouAreLookingFor") {

                  //do something    

           }

          

        }

        function EndRequestHandler(sender, args) {

            if (elem.toLowerCase == "YourElementID") {

                alert("that did it");

             }

        }

          </script>

Open in new window

0
 
LVL 1

Author Closing Comment

by:PatrickK_W
ID: 33634405
thanks guys - just the pointers that i needed
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

758 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

22 Experts available now in Live!

Get 1:1 Help Now