Basic help needed ASP.NET with C# code?

XerO

New member
Well... I'm an amateur to programming at the moment. Well we got this assignment on ASP.NET under the topic of Application Variables. As reference we were introduced to a basic code wherin we declared an Application["welcome"] = "Welcome to the page" variable in the Global.asax file under Application_Start and then calling it with Response.Write(Application["welcome"]) under Page_Load event in the aspx.cs file.
Now we are supposed to write the code for a simple hit counter using an Application Variable.
My solution was :

1) Global.asax file :
void Application_Start (...)
{
Application ["Counter"] = "0";
}

2) Under aspx.cs file :
protected void Page_Load(...)
{
int cntr = Convert.ToInt32(Application["Counter"]) + 1;
Response .Write("The page has been loaded " + cntr.ToString() + " times".);
Application["Counter"]=cntr.ToString();
}

Now my QUESTION is :
What if I want to go further and have two different counters - one for counting no. of times the page has been loaded and another for counting no. of times the Application has been executed. ?
Is there a way to go about doing this without using cookies and stuff ? Just plain Application variables and basic C# code...
I tried using two different application variables and trying out a few combinations placing them under Application and Session Start & End events and performing the increment under global.asax file itself instead of .cs file. But I could not attain any satisfactory results....
Perhaps someone could help me in this context...

Also can the difference between Page_Init and Page_Load events be used effectively in this context ?

Any suggestions appreciated... :)
 
Back
Top