Solved

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

Posted on 2009-07-02
3
551 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
[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
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

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…
The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 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