I have textbox “tb1” on my page and I want users to be able to add another if they need to input more data. I have the following code:
VB:
ViewState("num") = 2
Dim MyTextBox = New TextBox
MyTextBox.ID = "tb" & ViewState("num")
MyTextBox.Width = 540
MyTextBox.Height = 60
MyTextBox.TextMode = TextBoxMode.MultiLine
AddScript.Controls.Add(MyTextBox)
AddScript.Controls.Add(New LiteralControl("<br>"))
ViewState("num") = ViewState("num") + 1
ASP:
<asp:PlaceHolder id="AddScript" runat="server">
<asp:Label ID="Label2" runat="server" Font-Bold="true"
Text="Scripts: (Drag from right)"></asp:Label><br />
<asp:TextBox ID="tb1" runat="server" Width="90%" Height="60px"
TextMode="MultiLine" Enabled="false"></asp:TextBox>
</asp:PlaceHolder>
My problem is that I can only add one text box each time and I also have a search button for the right panel on the page and if this button is clicked the created textbox will disappear. Any help would be appreciated.
You could build your own TextBoxCollection CompositeControl which would enable you to achieve the functionality you require.
I have put together a basic example of how it could be achieved.
Control
Example Markup
Note: Change
Assembly="ASPNetWebApplication"to the name of your assembly.Example Codebehind
Hope this helps.