P
pedestrian via DotNetMonster.com
I'm having an issue with the button click event handler.
I follow this book example using the single-file method.
It is a very simple page with a Button and a label:
<script runat="server">
Sub Button1_Click(...)
Label1.Text = (Int32.Parse(Label1.Text) + 1).ToString
End Sub
...(omitted)
<asp:Button ID="Button1" Text="Add" OnClick="Button1_Click" runat="server" />
<asp:Label ID="Label1" Text="0" runat="server" />
...
This works as expected where a click on Button1 increase the
Label text by 1.
However, when I move the button handler part to the code behind file, a
Button1 click increase the Label text by 2! which is something I consider
strange.
But when I remove the OnClick attribute in the .aspx, it works as expected
again.
Is this signifies that if I'm using the code-behind method for button click
event
handler, there's ALWAYS no need to specify the OnClick attribute for the asp:
Button element?
I follow this book example using the single-file method.
It is a very simple page with a Button and a label:
<script runat="server">
Sub Button1_Click(...)
Label1.Text = (Int32.Parse(Label1.Text) + 1).ToString
End Sub
...(omitted)
<asp:Button ID="Button1" Text="Add" OnClick="Button1_Click" runat="server" />
<asp:Label ID="Label1" Text="0" runat="server" />
...
This works as expected where a click on Button1 increase the
Label text by 1.
However, when I move the button handler part to the code behind file, a
Button1 click increase the Label text by 2! which is something I consider
strange.
But when I remove the OnClick attribute in the .aspx, it works as expected
again.
Is this signifies that if I'm using the code-behind method for button click
event
handler, there's ALWAYS no need to specify the OnClick attribute for the asp:
Button element?