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
Solved

Ajax Timer in update panel causing 502 errors

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

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 …
Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
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 selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

809 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