views:

12

answers:

1

Hi, is it possible to render the same controls with different ID property ?

<%for (int i = 0; i < 15; i++)
  {%>
     <asp:Label ID='Label<%=i.ToString() %>' runat="server"/>
<%}%>

here is an error: 'Label<%=i.ToString() %>' is not a valid identifier.

+1  A: 

Yes, it is possible but from code behined, not WebForms mark-up. From WebForm mark-up you can add only "html" controls in loop, not "asp.net" controls.

From code behind you can do:

for( int i=0;i<15;i++)
{
    var l = new Label();
    Label.ID = "Label" + i;
    Controls.Add(l);
}
Alex Reitbort