Solved

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

Posted on 2009-07-02
3
550 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Today I am discussing AJAX problems in IE7 and I bet this will helps many guys out here who have problems with AJAX work. Lets start with the discovery of problem and then we will talk about its different solutions. My last two projects included …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

828 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