Click here to Skip to main content
16,006,001 members
Home / Discussions / C#
   

C#

 
GeneralRe: Real Time Applications Pin
Heath Stewart30-Sep-04 9:19
protectorHeath Stewart30-Sep-04 9:19 
GeneralEvil Textboxes Width Changes When Large Fonts (C#) Pin
dbromberg30-Sep-04 5:48
dbromberg30-Sep-04 5:48 
GeneralRe: Evil Textboxes Width Changes When Large Fonts (C#) Pin
leppie30-Sep-04 7:47
leppie30-Sep-04 7:47 
GeneralRe: Evil Textboxes Width Changes When Large Fonts (C#) Pin
dbromberg30-Sep-04 8:17
dbromberg30-Sep-04 8:17 
Generalstatic variable Pin
goatstudio30-Sep-04 5:32
goatstudio30-Sep-04 5:32 
GeneralRe: static variable Pin
Dave Kreskowiak30-Sep-04 6:01
mveDave Kreskowiak30-Sep-04 6:01 
GeneralRe: static variable Pin
goatstudio30-Sep-04 6:22
goatstudio30-Sep-04 6:22 
GeneralRe: static variable Pin
Heath Stewart30-Sep-04 6:22
protectorHeath Stewart30-Sep-04 6:22 
While I normally agree with Dave, I don't see this as specific to ASP.NET so I'll bite.

This won't even compile. You cannot declare fields (a static int Counter looks like a field to the compiler) inside method implementations.

If you need to declare a static variable, do so in the class (your derivative page) like so:
static int Counter = 0; // private
 
// Override OnEventName when possible - it's faster with more control
protected override void OnLoad(EventArgs e)
{
  Counter++;
  base.OnLoad();
}
This will increment for the lifetime of the object, which is alive for as long as the AppDomain is alive in which it was created. For Windows Forms applications, this is typically as long as your application is running (your application could, however, create a new AppDomain). With ASP.NET, this is for as long as the web application doesn't need restarting (like after editing the Web.config file for the site or application; or, again, unless you created a separate AppDomain for some reason).

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles]
GeneralRe: static variable Pin
goatstudio30-Sep-04 6:27
goatstudio30-Sep-04 6:27 
GeneralRe: static variable Pin
Heath Stewart30-Sep-04 6:42
protectorHeath Stewart30-Sep-04 6:42 
GeneralRe: static variable Pin
Dave Kreskowiak30-Sep-04 8:33
mveDave Kreskowiak30-Sep-04 8:33 
GeneralRe: static variable Pin
Heath Stewart30-Sep-04 9:10
protectorHeath Stewart30-Sep-04 9:10 
GeneralRe: static variable Pin
Dave Kreskowiak30-Sep-04 10:57
mveDave Kreskowiak30-Sep-04 10:57 
GeneralTransparent Panel Pin
MarkMokris30-Sep-04 5:28
MarkMokris30-Sep-04 5:28 
GeneralRe: Transparent Panel Pin
Heath Stewart30-Sep-04 6:32
protectorHeath Stewart30-Sep-04 6:32 
GeneralRe: Transparent Panel Pin
MarkMokris30-Sep-04 6:36
MarkMokris30-Sep-04 6:36 
GeneralRe: Transparent Panel Pin
Heath Stewart30-Sep-04 6:50
protectorHeath Stewart30-Sep-04 6:50 
Generalword formatting bar Pin
RomanD30-Sep-04 5:15
RomanD30-Sep-04 5:15 
GeneralRe: word formatting bar Pin
Dave Kreskowiak30-Sep-04 5:57
mveDave Kreskowiak30-Sep-04 5:57 
GeneralRe: word formatting bar Pin
RomanD30-Sep-04 6:09
RomanD30-Sep-04 6:09 
GeneralRe: word formatting bar Pin
Dave Kreskowiak30-Sep-04 7:21
mveDave Kreskowiak30-Sep-04 7:21 
GeneralUser clicks on dataGrid.... Pin
JDUK30-Sep-04 4:27
JDUK30-Sep-04 4:27 
GeneralRe: User clicks on dataGrid.... Pin
MarkMokris30-Sep-04 5:16
MarkMokris30-Sep-04 5:16 
GeneralDelegates, asynchronous invocation Pin
Serge Lobko-Lobanovsky30-Sep-04 3:52
Serge Lobko-Lobanovsky30-Sep-04 3:52 
GeneralRe: Delegates, asynchronous invocation Pin
Dave Kreskowiak30-Sep-04 5:29
mveDave Kreskowiak30-Sep-04 5:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.