Add asp control to page dynamically : Controls On Page « Page « ASP.Net






Add asp control to page dynamically

<%@ Page Language="vb" %>
<html>
   <head>
      <script runat="server">
         Sub Page_Load()
            If Not IsPostBack
               If Session.IsNewSession Then
                  Session("foo") = "foo"
                  Message.Text = "The current Session (SessionID: " & _
                     Session.SessionID & ") was created with this request."
               Else
                  Message.Text = "Click the button to abandon the current session."
                  Dim AbandonButton As New Button
                  AbandonButton.Text = "Abandon Session"
                  myForm.Controls.Add(AbandonButton)
               End If
            Else
               Session.Abandon()
               Message.Text = "Session abandoned."
            End If
         End Sub
      </script>
   </head>
<body>
   <form id="myForm" runat="server">
      <asp:label id="Message" runat="server"/>
   </form>
</body>
</html>

           
       








Related examples in the same category

1.Page.HasControls property
2.Find Control in a page
3.Add control by index