This is a migrated thread and some comments may be shown as answers.

Timer on Master Page causes child page life cycles to fire. Even though the Timer only triggers an update Panel.

3 Answers 70 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Sintayehu
Top achievements
Rank 1
Sintayehu asked on 30 Apr 2009, 06:06 PM

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 do logging in the methods I have in some of these page life cycle stages and If I happen to leave my user agent with a view of one of this pages, it will be logging every interval that the timer is set to. That is not desired.

Here is a pseudo example 

Master Page aspx  = Timer set to interval 30 sec , And Update panel with updatemode set to conditional

Master code behind = Page_load checkforEvent and if true update the panel.

 

 

******************************************************************************************************

Child page 1 inherits from Master page

Page load = Do something specific to the page and nothing to do with timer , by the way log what you do

 **************************************************

Child Page 2 inherits from Master page

 Page load = Do something specific to the page and nothing to do with timer,by the way log what you do

********************************

 

My expected result is ,

Go through page load and other page life cycles of the of the master page but not the children.

Apparently that is not the case.

Question is, How Can I stop the timer from firing my child page event handlers??

The sender in the page load of the child says it is the child page not the timer, so I cant say if timer skip what it usually does.

I also can't set a flag in the master page , like a session var to flag the timer because in ASP.net the child fires before the Master.

What to do,what to do?

Thanx!

3 Answers, 1 is accepted

Sort by
0
Sintayehu
Top achievements
Rank 1
answered on 04 May 2009, 07:57 PM
Basically All I need is find a way to detect who the sender is on page load,

Example ....

Child page Page_load(object sender, Eventarg e)

If (sender is not a Timer){
Do the regular page load
if(!ispostback){
//....
}
}

But I cant find a way to determine if the sender is a Timer!!! rather it comes in as the page it self.

Someone suggested I use the scriptmanager's  is in async mode property but since I have my script manager in the master page, it would say I am in Async mode every time my ajaxified pages do a callback! So I can't use that.

Thanx,  i am willing to experiment with any ideas out there.
0
TonyG
Top achievements
Rank 1
answered on 10 May 2009, 08:09 PM
I'm just starting to write code that uses a timer as you've described, so I'm also interested in a solution to the problem of having timers avoid collision with other control handlers. As to finding out who triggered the event and possibly avoiding life cycle events, I'm doing the following:
  string Source = "";  
  protected new void Page_Init( object sender , EventArgs e ) // overriding base class  
  {  
     Source = WhoFiredEvent();  
     // ...  
  }  
  protected new void Page_Load( object sender , EventArgs e )  
  {  
    // if user clicked menu, re-initialize page  
    if ( !Page.IsPostBack || Source.IndexOf("mnu") >= 0 )  
    { ... }  
  }  
  string WhoFiredEvent()  
  {  
     return Request.Form[ "__EVENTTARGET" ];  
     // TODO - may need to loop through Request.Form to find button or other controls  
  } 

This code could be made more elegant and it's subject to errors if you happen to check for IndexOf a non-unique string, but it's a good start and it's versatile.  I use it to check for "pnl", "grd" and entire control names like "grdReportList".

HTH
0
Shivek
Top achievements
Rank 1
answered on 11 Oct 2019, 06:18 AM
Did anyone figure out how to handle this? 
Tags
General Discussions
Asked by
Sintayehu
Top achievements
Rank 1
Answers by
Sintayehu
Top achievements
Rank 1
TonyG
Top achievements
Rank 1
Shivek
Top achievements
Rank 1
Share this question
or