asp.net, c#

Posted on 2012-09-17
Medium Priority
Last Modified: 2012-09-18
for i = 0 to 19
response.write "<input name=txtqty" & i & "><br>"

How to convert to asp.net/c#? I would like to use .net asp control in textbox as well.

Question by:solution1368
LVL 75

Accepted Solution

käµfm³d   👽 earned 2000 total points
ID: 38407737
Not the prettiest, but this would do it:

    for (int i = 0; i <= 19; i++)
        <asp:TextBox runat="server" ID="x"></asp:TextBox><br />
        x.ID = "txtqty" + i.ToString();

Open in new window

Do note that the Name property cannot be set for server controls due to how ASP.NET handles controls via naming containers (to ensure that controls can be uniquely identified for any particular page).

Author Comment

ID: 38407955
great. this is exactly what I need. Thanks

Expert Comment

ID: 38408672
If you want functionality similar to ASP then you should rather go to MVC and not to ASP.Net Web Controls.

MVC3 Razor Syntax. as below

   @for (int i = 0; i < 10; i++)
			 @Html.TextBox("Textbox" + i) <br />

Open in new window


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Loops Section Overview
Suggested Courses
Course of the Month16 days, 18 hours left to enroll

864 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