asp.net, c#

<%
for i = 0 to 19
response.write "<input name=txtqty" & i & "><br>"
next
%>

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

Thanks
solution1368Asked:
Who is Participating?
 
käµfm³d 👽Commented:
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).
0
 
solution1368Author Commented:
great. this is exactly what I need. Thanks
0
 
darjimaulikCommented:
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

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.