问题描述:
<%@page language="vb"%>
<%@ import namespace="system.io" %>
<script runat="server">
dim a as integer=0
sub page_load(sender as object,e as eventargs)
end sub
sub myfun(sender as object,e as eventargs)
a+=10
message.text=a
end sub
</script>
<html>
<body>
<form runat=server>
<asp:button id=mybutton text=单击 onclick="myfun" runat=server/>
<asp:label id=message runat=server/>
</form>
</body>
</html>
每一次单击为什么a还是显示10呢,要什么做才能显示10,20,30...
问题解答:
因为每次提交,都重新分配内存给变量a
每次提交都取上次的值,当然也可以用Cookies了
If IsPostBack Then
If message.Text <> "" Then
a = CInt(message.Text)
End If
End If
a += 10
message.Text = a
<asp:Label ID="message" runat="server" Text="0"></asp:Label>
a+=10 换成a=a+10