pitaridis
Well-known member
- Joined
- Nov 18, 2005
- Messages
- 63
- Programming Experience
- 10+
When I declare a variable in a form, every time I click a button, the value of the variable becomes 0. I have an example below. Can someone tell me what's wrong with the following code???
<%@ PageLanguage="VB" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<scriptrunat="server">
Shadows a AsNewInteger
ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs)
a += 1
Label1.Text = a
EndSub
</script>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="Button"/>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label></div>
</form>
</body>
</html>
<%@ PageLanguage="VB" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<scriptrunat="server">
Shadows a AsNewInteger
ProtectedSub Button1_Click(ByVal sender AsObject, ByVal e As System.EventArgs)
a += 1
Label1.Text = a
EndSub
</script>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Untitled Page</title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="Button"/>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label></div>
</form>
</body>
</html>