?
Solved

Dynamic ASP.NET Textbox ID

Posted on 2004-08-08
8
Medium Priority
?
573 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

777 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