Solved

div server control - set visibility

Posted on 2006-07-13
5
1,199 Views
Last Modified: 2012-06-22
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?

0
Comment
Question by:-Dman100-
5 Comments
 
LVL 5

Expert Comment

by:vinodhsomasekharan
ID: 17106028
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

0
 
LVL 10

Expert Comment

by:orbulat
ID: 17106041
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");
0
 

Author Comment

by:-Dman100-
ID: 17106134
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.
0
 

Author Comment

by:-Dman100-
ID: 17106163
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'
0
 
LVL 7

Accepted Solution

by:
pradeepsudharsan earned 500 total points
ID: 17106410
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now