Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now