473,586 Members | 2,652 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:TextBo x id="textName<%# i%>"/></td>
</tr>
</table>
<%
} %>

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

<table>
<% for (int i = 1; i < 3; i++) { %>
<tr>
<td>Name: </td>
<td><asp:TextBo x 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:TextBo x 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******** ******@TK2MSFTN GP09.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:TextBo x 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
2874
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 dynamically. From this page, users can check/uncheck each box, on submit button is clicked, I need to be able to read each checkbox's check status and write...
3
2964
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 do i add the EventHandler to it. Thanks RSB
2
1833
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. Any hint?
1
1869
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 form. The control needs to put together a simple design drawing for building constructors, based on some values in the Access form. Can it be...
2
9121
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 xmlns="http://LandAm.EAI.Mainframe.TSR.Schemas.TSSCallback"> <orderNo xmlns="">string</orderNo> <customerId xmlns="">string</customerId> <taxingAuthorityList xmlns=""> <string>string</string>...
3
4356
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? or if you know any third party control which act as a tool box control please let me know. Thanx in advance Yoshitha
3
2392
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
4468
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 of each unit, and the value of the inventory of that product. In addition, the GUI should display the value of the entire inventory, the additional...
15
5257
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 show - text boxes, input boxes, buttons, hyperlinks ie the usual. The data is not obtained directly from a database.
0
7912
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8202
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8216
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.