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
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
For i=1 To 25
Dim tb as textBox
tb=New TextBox()
tb.ID="FirstName" & i
tb.Columns=12
Page.Controls.Add(tb)
Next
Dim tb as textBox
tb=New TextBox()
tb.ID="FirstName" & i
tb.Columns=12
Page.Controls.Add(tb)
Next
ASKER
When i run that I get back an error
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
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
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
<%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
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
%>
<%
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Dim tb as textBox
tb=New TextBox()
tb.ID="FirstName" & i
Page.Controls.Add(tb)
Next