Solved

Dynamic ASP.NET Textbox ID

Posted on 2004-08-08
8
551 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
  • 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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 500 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP parse error 7 59
PHP PDO get the error if exists 3 88
API Soap Calls 4 112
Fulfillment API php code sample 1 39
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

776 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