日期:2014-05-19  浏览次数:20447 次

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 显示