<%@ Page Language="VB" %>

<script runat="server">
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        'Make sure the control has not already been added to the page
        If ((Session("WebUserControlAdded") Is Nothing) Or _
            (Not CBool(Session("WebUserControlAdded")))) Then
        
            Dim myForm As Control = Page.FindControl("Form1")
            Dim c1 As Control = LoadControl("Listing26-9.ascx")
            myForm.Controls.Add(c1)

            Session("WebUserControlAdded") = True
        End If
    End Sub
    
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        'Check to see if the control should be added to the page
        If ((Session("WebUserControlAdded") IsNot Nothing) And _
            (CBool(Session("WebUserControlAdded")))) Then

            Dim myForm As Control = Page.FindControl("Form1")
            Dim c1 As Control = LoadControl("Listing26-9.ascx")
            myForm.Controls.Add(c1)
        End If
    End Sub      
</script>


<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button"
            OnClick="Button1_Click" />
        <asp:Button ID="Button2" runat="server" Text="Button" />
    </div>
    </form>
</body>
</html>
