Friday, June 24, 2011

Saving Values in the State Bag

    <%@ 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>
       <font size="5">Sam's Teach Yourself ASP.NET in 21
      Days: Day 5 </font><hr><p>

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

No comments:

Post a Comment