473,386 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Create Control Dynamcially

In tradition ASP, i can create a template like follow

<%
for i = 1 to 3
%>
<table>
<tr>
<td>Name: </td>
<td><input type="text" name="textName<%=i%>"/></td>
</tr>
</table>
<%
next
%>

But how to do it in ASP.net? I have tried using like this

<%
for (int i = 1; i < 3; i++) {%>
<table>
<tr>
<td>Name: </td>
<td><asp:TextBox id="textName<%#i%>"/></td>
</tr>
</table>
<%
} %>

but it not works....thanks
Nov 20 '05 #1
1 1159
You were very close. This works, sort of :

<table>
<% for (int i = 1; i < 3; i++) { %>
<tr>
<td>Name: </td>
<td><asp:TextBox id="textName<%=i%>"/></td>
</tr>
<% } %>
</table>

If you view source, you'll see "textname1" and "textname2",
but that isn't very useful, is it ?

I say "sort of" because you can use this to repeat blocks of text,
with different font sizes, like the example in the QuickStart:
http://beta.asp.net/QUICKSTART/aspne...intro2_cs.aspx
but you cannot create controls with this type of code, because
as soon as you insert a second set of quotes into the line, i.e.,

<td><asp:TextBox id="textName<%=i%>" runat="server"/></td>

....the compiler will throw an exception.

So, you can use that type of code, to repeat any text,
IF you use only one set of quotes inside your brackets.

While <% %> code blocks provide a powerful way to custom manipulate
the text output returned from an ASP.NET page, they do not provide a
clean HTML programming model.

See :
http://beta.asp.net/QUICKSTART/util/...tro/intro3.src

As the sample above illustrates, developers using only <% %> code blocks
must custom manage page state between round trips and custom interpret posted values.

<%
This recommendation is from :
http://beta.asp.net/QUICKSTART/aspne...x#writingpages
%>

See intro2.aspx and intro3.aspx

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"ºa¤Ö" <ºa¤Ö@¼ö¶l.¤½¥q> wrote in message news:uF**************@TK2MSFTNGP09.phx.gbl...
In tradition ASP, i can create a template like follow

<%
for i = 1 to 3
%>
<table>
<tr>
<td>Name: </td>
<td><input type="text" name="textName<%=i%>"/></td>
</tr>
</table>
<%
next
%>

But how to do it in ASP.net? I have tried using like this

<%
for (int i = 1; i < 3; i++) {%>
<table>
<tr>
<td>Name: </td>
<td><asp:TextBox id="textName<%#i%>"/></td>
</tr>
</table>
<%
} %>

but it not works....thanks

Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Hardy Wang | last post by:
Hi all: I have a calendar control and a button in ASP.NET page. I will add one checkbox to each day cell in DayRender event. And based on some database values, some boxes will be checked...
3
by: RSB | last post by:
Hi Every one Having tuff time creating web controls Dynamically. All i am trying to do is read a table and generate a list of ASP TEXT Box. So how do i create this Control dynamically and where...
2
by: strout | last post by:
It's a pain to create each button with 2 images: button_on.gif button_off.gif I am looking for a control that have on/off two states, preferred as BACKGROUND images and with button text on it. ...
1
by: Arend Jan Nijenhuis | last post by:
Hi, I'm fairly new to .Net, but an expert in Microsoft Access VBA. For a large Access application, I want to create some sort of custom control (COM interop?) in VB.Net, to be used in an Access...
2
by: Thirsty Traveler | last post by:
How would I dynamcially create an XML document of the following form: <ReceiveTSSCallBack xmlns="http://LandAm.EAI.Mainframe.TSR"> <TSSCallBack...
3
by: Yoshitha | last post by:
Hi Is it possible to create my own tool box control (in c#.net) on which i can place the controls i've created or some other controls which already exisits? Can anyone tell me how to do this?...
3
by: Supriya | last post by:
Hi , Can anybody give me some information on how to create an activeX Control in C# with a Picturebox. Thank you, Supriya
3
by: 100grand | last post by:
Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.