读书人

aspx.vb 里面的变量,该如何解决

发布时间: 2012-03-04 11:13:34 作者: rapoo

aspx.vb 里面的变量
下面一个问题,请大家指点,1.aspx如下:
<%@ Page Language= "VB " %>
<script runat= "server ">

Protected temp as integer=1

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
If Not IsPostBack Then
temp=2
End If

End Sub

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

label1.text=temp

End Sub
</script>

<html xmlns= "http://www.w3.org/1999/xhtml " >
........................
</html>

为什么单击button1后 label1.text 会是1,其他地方都没有动过temp


[解决办法]
第一次进入页面,赋值为2
If Not IsPostBack Then
temp=2
End If
postback以后这个不执行,Protected temp as integer=1用的默认值
[解决办法]
第一次进入页面,赋值为2,没有显示出来
单击按钮,刷新页面
执行 Protected temp as integer=1
不执行下面
If Not IsPostBack Then
temp=2
End If
label1.text=1 显示

读书人网 >asp.net

热点推荐