Solved

Using timer and update panel on masterpage executes child page life cycle. How to avoid it ?

Posted on 2009-07-02
3
548 Views
Last Modified: 2012-05-07
I have a timer on my parent master page that checks for certain events and updates controls that I want through an updatePanel.

I have numerous child pages that inherit from the master page.

I get the desired effect of the timer checking for some event and updating the controls I specified.

The undesired effect is the timer will go through the selected(In View) child page --- page life cycle.

So if I have a code in  my Page_Init or Page_Load event handlers whatever is in them gets executed.

Doesn't render the html because it is a call back and only updates the control I specified like I wanted but, It seems unnessary that It goes through the page lifecycle of the child page.

I m developing a Instant Messenger in our web application using asp .net and c# wherein users are allowed to chat like gmail. I have one timer on master page that calls ajax function and updates its status as online or offline in database at 30 seconds time interval. And also checks any new message is arrived for the user. But it causes child page life cycle to execute at every call and executes page_ load event.

How can i avoid child page life cycle to execute?  
Question is, How Can I stop the timer from firing my child page event handlers??


Need solution urgently.
Thanks in advance.
MasterPage.aspx
 
<asp:Timer ID="TimerToCheckOnline" OnTick="TimerToCheckOnline_Tick" runat="server" Interval="30000" />
 
           <asp:UpdatePanel ID="FieldUpdatePanel1" UpdateMode="Conditional" runat="server">
                <Triggers> 
                <asp:AsyncPostBackTrigger ControlID="TimerToCheckOnline" />
                </Triggers>        
                <ContentTemplate>                
                 </ContentTemplate> 
            </asp:UpdatePanel>
 
 
 MasterPage.aspx.cs
 
 protected void TimerToCheckOnline_Tick(object sender, EventArgs e)
 {
            UpdateOnlineOfflineStatus(userCode);                             
            GetNewMessage(UserCode);
}

Open in new window

0
Comment
Question by:Suhashk
  • 2
3 Comments
 
LVL 18

Expert Comment

by:David Robitaille
ID: 24794228
sorry, but you cannot.
The way UpdatePanel are made, they have to run trough the full page life cycle.
The problem is a masterpage dont exist as a page itself, it must have a "child page" in order to "exist".
By the way, you should not "update" all your sutff within the page load (or at least use a "if not page.IsPostBack" clause). there is the viewstate mechanism for that.
0
 

Author Comment

by:Suhashk
ID: 24822000
Thank you  for your reply...

But some times we may need to write code outside page.IsPostBack..in such situation it will cause a problem.
For now i have come across a temporary solution..ie instead of using timer on master page i have placed my code in page_load event of master page...so that online offline status are updated with any of the serverside calls..but this is not a good solution as users cannot get the updated status until their is a postback..Can u suggest anything so that this functionality can be achieved?  :-)


Thanks in Advance
0
 
LVL 18

Accepted Solution

by:
David Robitaille earned 500 total points
ID: 24822409
Humm... i never did that before.

But i think i read someware that you could do something like this using WebService. Here, i fond this one :

http://www.developer.com/net/asp/article.php/10917_3657826_1

Anyway, ther's a lot of those Webservice tutorials on the web. the idea is to build a asp.net Webservice and then the update is called using javascript instead of an update panel, this way you dont need to postback...

But, hey, i think i just fond something else

http://encosia.com/2007/07/25/display-data-updates-in-real-time-with-ajax/

it use a static webmethod. I got to read about this later. but i think THAT should help...
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

There is basically two types of AJAX request in mootools. Request  and Request.HTML Request: Request is the basic XHR request class in MooTools. While not extremely useful on its own, it provides the basic functionality for both Request.HTM…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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