1

im a newbie in asp.net and i have a issue. i need to make my div section visible only on some pages. i placed attribute style:(not with " on start of course)

<div ID="id1" class="grid-box width33 grid-h" style="visibility:visible" >
    <!-- Other code here //-->
</div>

and i need to make in code behind some kind of if statement that's going to check if my section picker picked that div section, and if it is picked it's going to be printed on page, else it's going to render something else. on my page_load method i have a code such as:

if (this.CurrentContent.CentralSection.HasValue)
{
    this.ucCentralSection.CentralSectionId = this.CurrentContent.CentralSection.Value;
}
else
{
    this.ucCentralSection.Visible=false;
}

but it's not working properly...

2 Answers 2

0

Add a runat attribute to your div. Use FindControl method in your code-behind to locate the div in question and toggle the visible property there.

0

Use like this

 <div ID="id1" class="grid-box width33 grid-h" style="visibility:visible" 
                  runat="server" >
   <!-- Other code here //-->
 </div>

And in your cs page

 var div = (HtmlGenericControl)Page.FindControl("id1");
 div.Visibility=true;

Other wise you can use Panel server control.

3
  • 1
    but in visual studio 2013:Error 8 'System.Web.UI.HtmlControls.HtmlGenericControl' does not contain a definition for 'Visibility' and no extension method 'Visibility' accepting a first argument of type 'System.Web.UI.HtmlControls.HtmlGenericControl' could be found (are you missing a using directive or an assembly reference?) Commented Jul 31, 2014 at 14:25
  • 1
    you can use attribute set visibility there like div.Attribute.Add("visibility","") or you can use css "display","none" Commented Aug 2, 2014 at 4:34
  • Just use the Visible property of the HtmlGenericControl in code behind.
    – NetMage
    Commented Jun 4, 2021 at 21:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.