Add asp:TextBox to page dynamically (VB.net) : Load Control « Page « ASP.Net






Add asp:TextBox to page dynamically (VB.net)

<%@ Page Language=VB Debug=true %>
<script runat=server>
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)

End Sub
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
    Dim I as Integer
    For I = 1 to txtNumber.Text
        Dim MyTextBox = New TextBox
        MyTextBox.ID = "txtDynamic" & I
        MyTextBox.Text = "Control Number: " & I
        frmMyPage.Controls.Add(MyTextBox)
        Dim MyLiteral = New LiteralControl
        MyLiteral.Text = "<BR><BR>"
        frmMyPage.Controls.Add(MyLiteral)
    Next
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Creating a Basic TextBox Control</TITLE>
</HEAD>
<form 
    id="frmMyPage"
    runat="server"
>
Enter the number of TextBox controls you want:<BR>
<asp:TextBox 
    id="txtNumber" 
    Columns="25"
    MaxLength="3"
    runat=server 
/>
<BR><BR>
<asp:button 
    id="butOK"
    text="OK"
    Type="Submit"
    OnClick="SubmitBtn_Click" 
    runat="server"
/>
<BR><BR>
</Form>
</BODY>
</HTML>
           
       








Related examples in the same category

1.LoadControl method example (VB.net)
2.Find control in a page (C#)
3.Use propery defined in asp.net control (C#)
4.Pass parameter to page control (C#)