c# - li with runat server -


i have problem creating dynamic <li> elements codebehind. need assign runat server li, didnt find way assign runat server, can't find li control when need change attributes code behind. there answer problem? new asp.net c#.

here code:

<ul class="nav nav-tabs" runat="server" id="tablist">      //first got ul control assign runat=server in aspx page </ul>  //then create li 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 not working tab.controls.add(new literalcontrol("<a href=\"#customer" + (i + 1) + "\" data-toggle=\"tab\">penumpang " + (i + 1) + "</a>"));  //then add li ul controler called tablist this.tablist.controls.add(tab); 

my problem is, when page loads, can see li on page, cannot call li code behind when need it. there way call li in code behind? or change li attributes when assigned dynamically? sorry bad english.

thanks in advance.

the reason why cannot access <li> in code-behind because dynamically generated.

dynamically generated controls lose state when rendered on view , access them again in code-behind when postback occurs, need recreate them before playing them. basically, need recreate them everytime on postback access properties , values , manipulate them.

also, runat='server' wont work code-behind. instead of using <li>, try using asp.net controls such listview or other data-binding controls.

hope helps.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -