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

x
?
Solved

Ajax Timer in update panel causing 502 errors

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

Technology Partners: 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

Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
This article discusses how to implement server side field validation and display customized error messages to the client.
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
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…

664 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