Live Chat Icon For mobile
Live Chat Icon

How to create an array of Web Controls

Platform: ASP.NET| Category: TextBox

<asp:PlaceHolder id='PlaceHolder1' runat='server'></asp:PlaceHolder>

VB.NET


Dim textboxes(5) As TextBox
Dim i As Integer
For i = 0 To 4
   	textboxes(i) = New TextBox()
	textboxes(i).ID = 'TextBox' + i
   	textboxes(i).AutoPostBack = True
   	PlaceHolder1.Controls.Add(textboxes(i))
Next 

C#


TextBox[] textboxes = new TextBox[5]; 
for (int i=0; i<5; i++) 
{ 
	textboxes[i] = new TextBox(); 
	textboxes[i].ID = 'TextBox' + i; 
	textboxes[i].AutoPostBack = true; 
	PlaceHolder1.Controls.Add(textboxes[i]); 
}

Share with