0

Project with Master Page c#

i want to change the visibility (True / False) of a <li> in a <div> programmatically.

master_page

<div id="div_admin">
  <ul>
    <li style="margin-left:-30px; margin-bottom:5px" id="li_soli">Soli</li>
  </ul>
</div>

master_page C#

If(listParametro.Count(); > 0){
    <li> need to go Visible False
} else {
    <li> need to go Visible true
}

The problem would be how to call the LI object through its ID to change its visibility

Peter B
  • 22,460
  • 5
  • 32
  • 69
StudySteam
  • 35
  • 5

2 Answers2

3

Use <li runat="server">, and then you can do li_soli.Visible = whatever you like.

Note that this will change the id that it gets in the browser to a generated (derived) id value. There are workarounds to deal with that issue, see e.g. here: How to set specific ID for server controls in an ASP.NET Web Form that is using a MasterPage?

Peter B
  • 22,460
  • 5
  • 32
  • 69
-1

You can also use asp.net panel to hide and show

 <asp:Panel ID="Panel1" runat="server" Visible="false">
  <li> need to go Visible False
  </asp:Panein ll>

 <asp:Panel ID="Panel2" runat="server" Visible="false">
  <li> need to go Visible 
  </asp:Panel>

In page load method you can write your condition according to you need.

Mr doubt
  • 51
  • 1
  • 10
  • 42