Re: How can I find the components added to web form? (Urgent)

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Steven Cheng[MSFT] (v-schang_at_online.microsoft.com)
Date: 09/10/04


Date: Fri, 10 Sep 2004 02:25:34 GMT

Hi Martin,

>From your description, you put a .net Timer component on the ASP.NET web
page and want to access this timer from a certain control on that page,
yes? As for this problem, here are some of my suggestions:

1. The timer is not a UI control so it is not added into control collection
and just be a member of the page class. So from a sub control on the page,
there isn't any buildin means to find the component. The only way is if we
know the web page's page class and explicitly access the timer through the
page's member. For example, we define a common base page class which has a
timer member field , then, we can access all those pages derived from the
base page as the base page class instance.

2. SINCE ASP.NET web page is request/response based, so the page's
lifecycle is only between the request comming to the server and the
respsonse be returned to client. Also, any components on the page also only
exist during the page's lifecycle. So I think use a timer at page level
won't work as what we expect because everytime a page is request, a new
timer is constructed and when the page is rendered out and unloaded , the
timer is also disposed. If you do want to do some repeatedly tasks
everytime a page is loaded on the serverside, or constantly post back a
page after a period of time, you can consider Cor 's suggestion about using
the client javascript "setTimeout" to constanly post back the page.
Also, here is a tech article discussing on building such a custom timer
server controL:

#Build a Custom AutoPostBack ASP.NET Page Timer ServerControl
http://www.eggheadcafe.com/articles/20021006.asp

In addition, in asp.net it's ok for us to build a Application scope
background timer which execute over the application's lifecycle and do some
background schedule tasks,here is also a blog thread discussing on this:

#Scheduled Execution in ASP.NET
http://weblogs.asp.net/ashben/archive/2003/10/11/31579.aspx

Also, I've also tried build a appliation level background and store it in
ApplicationState collection, that also works, for example:

protected void Application_Start(Object sender, EventArgs e)
{
        System.Threading.Timer timer1 = new System.Threading.Timer(new
System.Threading.TimerCallback(this.CheckStatus),null,0,3000);
        Application["timer"] = timer1;
}

Hope helps..

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)



Relevant Pages

  • Re: Lahman, how ya doing?
    ... >things like Thermometer, Computer, Filter, Beam, etc. for objects. ... >> control blocks from. ... >Is Timer a true event generator? ... >queue structure. ...
    (comp.object)
  • Re: Lahman, how ya doing?
    ... >> target is around 14 seconds, much longer than any delays in the control ... >queue manager program unit and a Timer program unit that gets ticks from ... the Thermometer object reads an attribute in the simulation ... executes at a particular time, ...
    (comp.object)
  • Re: Havent done anything real with OOP yet.
    ... > The heatsink has its own control loop, thermometer, and heater. ... by the analog timer, one might just need: ...
    (comp.object)
  • Re: Threading - Is this Ok?
    ... panel using a Timer control. ... So client will not see any progress. ... requests to server to refresh progress. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Problem writing Time-Out function
    ... The problem is that the timer will not fire until you get back to the main message pump, ... which you won't do because the library blocks (it may or may not be in an "infinite ... Because the GUI thread is blocked, ... problems later (particularly if the library is an ActiveX control or some other control ...
    (microsoft.public.vc.mfc)