Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Ajax Timer in update panel causing 502 errors

Posted on 2010-08-27
3
Medium Priority
?
1,122 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 1000 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 1000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.
Suggested Courses

824 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