Solved

Dynamic ASP.NET Textbox ID

Posted on 2004-08-08
8
529 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
Comment Utility
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
Comment Utility
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
Comment Utility
When i run that I get back an error

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
0
 
LVL 35

Expert Comment

by:YZlat
Comment Utility
did you use my code?

take out <% %> from your code-behind file? you don't need them
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 35

Expert Comment

by:YZlat
Comment Utility
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
Comment Utility
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
Comment Utility
again, you don't need <% %>
0
 
LVL 35

Accepted Solution

by:
YZlat earned 500 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Convert XML schema file to XML file 7 76
css border raidius issue 7 74
How to analyze web traffic logs 10 89
Grunt No Clean Targets 6 53
There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now