Re: Scope of variables in C# script section of an ASP.NET page
- From: "ViewState" <oakcool@xxxxxxxxx>
- Date: Wed, 12 Oct 2005 23:34:42 -0300
ASP.NET application are state less, they open and close in each post back,
so you won't have your variable set in the next time you do apost back.
I don't know if I got your scenario right but I think you need a session. so
you create the instance of your class, put in the values you want then you
put it in the session
"Peter" <spam@xxxxxxxxxxxxxxx> escreveu na mensagem
news:K5Cdnep-d8NNNNDeRVn-hg@xxxxxxxxxxxxxx
> One question that came up is that I am writing an ASP.NET page that has
> some custom (C#) web controls. Since I am not afforded the ability to
> write
> to the console for debugging/information purposes I thought I would simply
> write things to a logfile. Well I instantantiated my custom C# class
> outside
> the page_load function thinking it would only get constructed once and
> then
> get skipped over on refreshes of the IE browser. However apparently there
> seems to be no way around this. Basically I want to have the class as
> global
> class that some of the other C# script functions can access.
>
> My thinking was I could open up a TextWriter in the constructor of the
> global
> class and then close the file in the destructor. My thinking is flawed in
> a couple
> of points. I was thinking that the class would get instantiated once if it
> was outside
> of the page_load and the destructor would kick off if you left the page
> for another
> page. So my new tack is to open the file, insert my messages then quickly
> close
> it back up. Seem reasonable or is it doable to instantiate a class once
> upon
> initially loading of a page and have it available throughout the C#
> script?
>
> BTW, this C# scripting seems to be dissimilar to plain old C#
> applications. I was trying
> to call DateTime.Now but couldn't. Should I have available to me all the
> functions
> that are available in a plain old C# windows application? Are there any
> good reference
> materials on the C# (ASP.NET) scripting particulars that someone could
> recommend?
> Any information would be greatly appreciated!
>
> Thanks,
> Peter
>
.
- References:
- Prev by Date: Re: ASP.NET 2.0 Membership Login event
- Next by Date: Re: ASP.NET 2.0 Membership Login event
- Previous by thread: Scope of variables in C# script section of an ASP.NET page
- Next by thread: Re: Scope of variables in C# script section of an ASP.NET page
- Index(es):
Relevant Pages
|