A
Arpan
Consider the following ASPX code snippet:
<script language=VB runat=server>
Sub Page_Load(obj As Object,ea As EventArgs)
If Not(Page.IsPostBack) Then
ViewState("STime")=DateTime.Now
lblMessage.Text="The time now is " & ViewState("STime")
End If
End Sub
Sub btnClick(obj As Object,ea As EventArgs)
lblMessage.Text="The time now is " & DateTime.Now
lblMessage.Text+="<br>You arrived at the previous page at: " & ViewState("STime")
End Sub
</script>
<form runat=server>
<asp:Button id="submit" Text="SUBMIT" OnClick="btnClick" runat=server/>
<asp:Label id="lblMessage" runat=server/>
</form>
As is evident from the code, the btnClick method is accessing the variable ViewState("STime") but how can the btnClick access the ViewState variable which has been created in the Page_Load method? Are ViewState variables equivalent to ASP Session variables? Can ViewState variables be accessed by any other method/function?Also can variables that have been declared & assigned values in the Page_Load method be accessed by other methods/event handlers?
Newbie......please help
Thanks,
Arpan
<script language=VB runat=server>
Sub Page_Load(obj As Object,ea As EventArgs)
If Not(Page.IsPostBack) Then
ViewState("STime")=DateTime.Now
lblMessage.Text="The time now is " & ViewState("STime")
End If
End Sub
Sub btnClick(obj As Object,ea As EventArgs)
lblMessage.Text="The time now is " & DateTime.Now
lblMessage.Text+="<br>You arrived at the previous page at: " & ViewState("STime")
End Sub
</script>
<form runat=server>
<asp:Button id="submit" Text="SUBMIT" OnClick="btnClick" runat=server/>
<asp:Label id="lblMessage" runat=server/>
</form>
As is evident from the code, the btnClick method is accessing the variable ViewState("STime") but how can the btnClick access the ViewState variable which has been created in the Page_Load method? Are ViewState variables equivalent to ASP Session variables? Can ViewState variables be accessed by any other method/function?Also can variables that have been declared & assigned values in the Page_Load method be accessed by other methods/event handlers?
Newbie......please help
Thanks,
Arpan