Link to home
Start Free TrialLog in
Avatar of jui2ce
jui2ce

asked on

Dynamic ASP.NET Textbox ID

I am trying to have a sheet that you add upto 25 items at a time

For i = 1 to 25
   <asp:TextBox id='FirstName<%# + i %>'  Columns="12" Runat="Server" />" )

Next

However I can not get the id part to take?

Please Help ASAP
Avatar of YZlat
YZlat
Flag of United States of America image

For i=1 To 25
   Dim tb as textBox
   tb=New TextBox()
   tb.ID="FirstName" & i
   Page.Controls.Add(tb)
Next
For i=1 To 25
   Dim tb as textBox
   tb=New TextBox()
   tb.ID="FirstName" & i
   tb.Columns=12
   Page.Controls.Add(tb)
Next
Avatar of jui2ce
jui2ce

ASKER

When i run that I get back an error

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
did you use my code?

take out <% %> from your code-behind file? you don't need them
you could also try this:

<%For i = 1 to 25%>
   <asp:TextBox id="FirstName<%=i %>" Columns="12" Runat="Server" />" )

<%Next%>

But I strongly recomend you use a method I provided before
Avatar of jui2ce

ASKER

When I try to use the method you provided before it erros out with that error.
<%
For i=1 To 25
   Dim tb as textBox
   tb=New TextBox()
   tb.ID="FirstName" & i
   tb.Columns=12
   Page.Controls.Add(tb)
Next

%>
again, you don't need <% %>
ASKER CERTIFIED SOLUTION
Avatar of YZlat
YZlat
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial