Nevena
Nevena

Reputation: 37

div section visibility true/false on certain pages asp.net

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...

Upvotes: 1

Views: 9989

Answers (2)

शेखर
शेखर

Reputation: 17614

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.

Upvotes: 0

IrishChieftain
IrishChieftain

Reputation: 15253

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.

Upvotes: 0

Related Questions