coder coder - 6 months ago 9
Javascript Question

Disable <li> tag based on value of a key in web.config file

C#

string fblink = WebConfigurationManager.AppSettings["facebook"];
if (fblink == "")
{
//need code to disable <li>
}


HTML

<div >
<ul>
<li id="face">
<a id="fb" runat="server" target="_blank" href="<%$ AppSettings:facebook %>"></a>
</li>
</div>


In web.config file added a key named facebook with value.

If this value is empty the li tag should disable

Answer

If you want to access the <li> in back-end means you should give runat="server" as tag attribute. if so The li will looks like the following:

<li id="face" runat="server"> .. </li>

So that you can access them like this:

if (fblink == "")
{ 
   face.Visible=false;
}  

By using javascript:

var fblink = '<%= System.Configuration.ConfigurationManager.AppSettings["facebook"].ToString() %>';
if (fblink == "")
{ 
  var liElement =  document.GetElementByID("face");
  liElement.style.display = 'none'; 
}