F
Francois
I have the following ASP.NET page :
<!-- event.aspx -->
<%@ Page Language="C#" %>
<html>
<script runat=server>
protected int counter;
protected void OnClickMyButton(object src, EventArgs e)
{
counter++;
_message.InnerText = "You clicked the button " + counter + "
times!";
}
protected void Page_Init(object src, EventArgs e)
{
_MyButton.ServerClick += new EventHandler(OnClickMyButton);
}
</script>
<body>
<form runat=server ID="Form1">
<h2>ASP.NET event page</h2>
<p>
<input type=button id=_MyButton value="Click me!" runat=server
NAME="_MyButton"/>
</p>
<span id=_message runat=server/>
</form>
</body>
</html>
I expect that each time i click on the button, a new HTTP GET method
is sent to the server and the click event would call the
OnClickMyButton method which would increase the value of the counter
on each click.
But the counter never gets incremented, then I believe that i
misunderstand something in the mechanism, either the counter loose his
value between each click or after the first click the event does not
occur anymore or ... i don't tknow...
Please could u explain me how to keep a value between different call
of the same page? And what is the real mechanism each time that i
click on the button?
Thank you.
Francois
<!-- event.aspx -->
<%@ Page Language="C#" %>
<html>
<script runat=server>
protected int counter;
protected void OnClickMyButton(object src, EventArgs e)
{
counter++;
_message.InnerText = "You clicked the button " + counter + "
times!";
}
protected void Page_Init(object src, EventArgs e)
{
_MyButton.ServerClick += new EventHandler(OnClickMyButton);
}
</script>
<body>
<form runat=server ID="Form1">
<h2>ASP.NET event page</h2>
<p>
<input type=button id=_MyButton value="Click me!" runat=server
NAME="_MyButton"/>
</p>
<span id=_message runat=server/>
</form>
</body>
</html>
I expect that each time i click on the button, a new HTTP GET method
is sent to the server and the click event would call the
OnClickMyButton method which would increase the value of the counter
on each click.
But the counter never gets incremented, then I believe that i
misunderstand something in the mechanism, either the counter loose his
value between each click or after the first click the event does not
occur anymore or ... i don't tknow...
Please could u explain me how to keep a value between different call
of the same page? And what is the real mechanism each time that i
click on the button?
Thank you.
Francois