Link to home
Start Free TrialLog in
Avatar of -Dman100-
-Dman100-Flag for United States of America

asked on

div server control - set visibility

I have created a master page for my site and have a div server contorl:

<div id="leftcolumn" runat="server">'

I want to be able to set the visibility of this control for my different pages.

Whenever the a page renders, the source shows:

<div id="ct100_leftcolumn">

So, first off, the styles for the control don't apply because the id is different than what I specified when the page renders.  Secondly, I can't set the visibility for the control in the code-behind.

What is the appropriate way to handle this?

Avatar of vinodhsomasekharan
vinodhsomasekharan

Hai,

From serverside u can Remove/set the visibility of the div control by
myDiv.Style.Add("visibility", "hidden")
myDiv.Style.Add("visibility", "visible")

Hope this helps

Regards
Vinodh

the source shows "ct100_leftcolumn" because it's inside another control like user control or place holder / datagrid ..etc....

of u can update your javascript function to reference the id "ct100_leftcolumn"

as vinodh said, u can use leftcolumn.Style.Add("xxxx","xxxxx"); or leftcolumn.Attributes.Add("xxxx","xxxxx");
and remove leftcolumn.Attributes.Remove("xxxx");
Avatar of -Dman100-

ASKER

Would a master page be considered another control?  The div server control sits inside the master page.

Here is how my master page looks:

<%@ Master Language="C#" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
 <title>Company Title</title>
 <link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="container">
<div id="topnav">
<table cellSpacing="0" cellPadding="0" border="0">
<colgroup span="1" align="left" width="50%">
</colgroup>
<colgroup span="1" align="right" width="50%">
</colgroup>
<tr>
<td>&nbsp;</td>
<td>
<form style="MARGIN: 0px" name="frmSearch" action="" method="post">
Search <input type="text" size="25" name="txtQuery"> <A href="javascript:document.frmSearch.submit()">
<IMG src="images/go.gif" align="absMiddle" border="0"></A>
</form>
</td>
</tr>
</table>
</div>
<div id="header">
<table border="0" cellpadding="0" cellspacing="0">
<colgroup width="25%" bgcolor="#ffffff" span="1">
</colgroup>
<colgroup width="75%" span="1">
</colgroup>
<tr>
<td>
<img src="images/CL_4C_75px.gif" alt="CompassLearning: Better Technology for Improved Student Achievement">
</td>
<td class="hdrgradient">&nbsp;</td>
</tr>
</table>
</div>
<div id="main">
<div id="leftcolumn" runat="server">This is the left column navigation bar</div>
<div id="rightcolumn" runat="server">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</div>
<div id="footer">This is where the footer goes</div>
</div>
</body>
</html>


So, when I create new pages and add the MasterPageFile in the Page directive, I want to be able to control the visibility of the <div id="leftcolumn" runat="server"> in the MasterPageFile and turn on or off the visibility of the div server control.
As a follow-up, I tried the following in the code-behind for the pages I want to turn off the visibility of the leftcolumn div:

public partial class index : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        leftcolumn.Style.Add("visibility", "hidden");
    }
}

Which gave me the error: 'leftcolumn does not exist in the current context'
ASKER CERTIFIED SOLUTION
Avatar of pradeepsudharsan
pradeepsudharsan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial