Solved

Ajax Timer in update panel causing 502 errors

Posted on 2010-08-27
3
1,110 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
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.
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

786 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