Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Dynamic ASP.NET Textbox ID

Posted on 2004-08-08
8
Medium Priority
?
580 Views
Last Modified: 2010-04-06
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
0
Comment
Question by:jui2ce
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
8 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 11751595
For i=1 To 25
   Dim tb as textBox
   tb=New TextBox()
   tb.ID="FirstName" & i
   Page.Controls.Add(tb)
Next
0
 
LVL 35

Expert Comment

by:YZlat
ID: 11751787
For i=1 To 25
   Dim tb as textBox
   tb=New TextBox()
   tb.ID="FirstName" & i
   tb.Columns=12
   Page.Controls.Add(tb)
Next
0
 

Author Comment

by:jui2ce
ID: 11759084
When i run that I get back an error

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:YZlat
ID: 11759339
did you use my code?

take out <% %> from your code-behind file? you don't need them
0
 
LVL 35

Expert Comment

by:YZlat
ID: 11762703
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
0
 

Author Comment

by:jui2ce
ID: 11765301
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

%>
0
 
LVL 35

Expert Comment

by:YZlat
ID: 11765370
again, you don't need <% %>
0
 
LVL 35

Accepted Solution

by:
YZlat earned 2000 total points
ID: 11765378
just use

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

no <% %> tags
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question