I have a problem with creating dynamic <li> elements from codebehind. I need to assign runat server to li, but I didnt find a way to assign runat server, so I can't find that li control when I need to change the attributes from code behind. Is there any answer to my problem? I am new to asp.net c#.

Here is my code:

<ul class="nav nav-tabs" runat="server" id="tabList">
     //First i got ul control that i assign runat=server in aspx page
</ul>

//then i create li from code behind in Page_Init()
System.Web.UI.HtmlControls.HtmlGenericControl tab = new System.Web.UI.HtmlControls.HtmlGenericControl("li");
tab.ID = "tab" + (i + 1);
tab.Attributes.Add("runat", "server");//this is not working
tab.Controls.Add(new LiteralControl("<a href=\"#customer" + (i + 1) + "\" data-toggle=\"tab\">Penumpang " + (i + 1) + "</a>"));

//then i add the li to my ul controler called tablist
this.tabList.Controls.Add(tab);

My problem is, when the page loads, I can see the li on the page, but I cannot call li from the code behind when i need to do something with it. Is there any way to call the li in code behind? Or change the li attributes when it is assigned dynamically? Sorry for bad English.

Thanks in advance.

Related posts

Recent Viewed