views:

1463

answers:

2

Hi,

I have a ul list with a number of list items like:

<ul>
<li runat="server" id="liOne">one</li>
<li runat="server" id="liTwo">two</li>
<li runat="server" id="liThree">three</li>
</ul>

On page load, I need to set these list items visible or not visible.

For some reason I cannot access these in the C# code behind. Nor are the list items being generated for the designer file. Does anyone have any suggestions how to get this to work?

I get this error:

The name 'liOne' does not exist in the current context

Many thanks.

+1  A: 

It should work. Try rebuilding and restarting visual studio.

Then try deleting the designer file and right-clicking on the page and selecting "convert to web application" - if indeed it is already a web application.

Neil Trodden
I tested this and indeed it should work +1
Jose Basilio
I've tried it all. Still a no go. Any other suggestions?
A: 

Your code may be wrapped with some server control that does not allow direct references by ID. If so, you may access your inner elements of this wrapper by writing this:

var li = wrapperElement.FindControl("liOne") as HtmlGenericControl;

Hope this helps.

Ivan Suhinin