Save value to view state (VB.net) : Post Back « Page Lifecycle « ASP.NET Tutorial






<%@ Page Language="VB" %>

<script runat="server">
   Sub Page_Load(Sender as Object, e as EventArgs)
      if not Page.IsPostBack then
         ViewState("StartTime") = DateTime.Now      
         lblMessage.Text = "The time is now: " & _
            ViewState("StartTime")
      end if
   end sub
   
   Sub Submit(obj as object, e as EventArgs)
      lblMessage.Text = "The time is now: " & DateTime.Now & _
         "<br>started at: " & ViewState("StartTime")
      
   end Sub
</script>

<html><body>
   <form runat="server">
      <asp:Button id="btSubmit" runat="server" Text="Submit"
         onClick="Submit" />
      
      <asp:Label id="lblMessage" runat=server />
   </form>
</body></html>








5.5.Post Back
5.5.1.Page.IsPostBack (C#)
5.5.2.Save value to view state (VB.net)