because
Private constj As Integer=0
always reset the value to 0tryPrivate Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click if ViewState("Myvalue") is nothing then
ViewState("Myvalue") = 0
end if constj = CType(ViewState("Myvalue"),Integer) + 1
ViewState("Myvalue") = constj Me.Label1.Text = constj.ToString()
End Sub
Private constj As Integer=0
always reset the value to 0tryPrivate Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click if ViewState("Myvalue") is nothing then
ViewState("Myvalue") = 0
end if constj = CType(ViewState("Myvalue"),Integer) + 1
ViewState("Myvalue") = constj Me.Label1.Text = constj.ToString()
End Sub
那么,Label1.Text显示的就总是 1 ;
你可以使用Session["constj"](或application)来存放全局变量,
if Session["constj"]=NULL
then Session["constj"]=0
else Session["constj"]=(int)Session["constj"]+1;
因為的變量每次補刷新.就還原了.可用viewstate存下來.