A page without the sidebar?

Mar 6, 2009 at 11:04 PM
I am using the Portraitpress theme and I have several gridviews that I use to display hiking data, I would like to have them on a page without the sidebar as the gridview goes into the sidebar . Thanks for your help.

http://www.sahcinfo.org/scheduled_hikes.aspx
Coordinator
Mar 7, 2009 at 1:22 AM
I'm guessing that scheduled hikes page is a separate ASPX page you created?  IOW, it's not a typical BE page, right?

Here's what you can do.  For step # 4, there's a small difference depending on whether you have a code-behind page for scheduled_hikes.aspx.

1. In your site.master file (in the PortraitPress theme), wrap the sidebar in a PlaceHolder:

<asp:PlaceHolder ID="phSidebar" runat="server">
    <div id="sidebar">
        <blog:WidgetZone runat="server" ID="rightzone" />
    </div>
</asp:PlaceHolder>

2. In your site.master.cs file, add this:

protected void Page_PreRender(object sender, EventArgs e)
{
    if (phSidebar.Visible)
        Form1.Attributes.Add("class", "body");
    else
        Form1.Attributes.Add("class", "body noSidebar");
}

3. In your style.css file, below the CSS definition for #content (where a width of 570px is defined), add this new CSS class:

form.noSidebar #content{
    width:100%;
}

4. If you have a code behind file for this page (i.e. scheduled_hikes.aspx.cs), then in the Page_Load event handler, add the following.  If you have a code behind file, but don't have a Page_Load event handler, then just add the entire Page_Load event handler below:

protected void Page_Load(object sender, EventArgs e)
{
    PlaceHolder phSidebar = Master.FindControl("phSidebar") as PlaceHolder;
    if (phSidebar != null)
        phSidebar.Visible = false;
}

If you don't have a code behind file, then in your scheduled_hikes.aspx page, before the <asp:Content> tag, add:

<script runat="server">
    
    protected void Page_Load(object sender, EventArgs e)
    {
        PlaceHolder phSidebar = Master.FindControl("phSidebar") as PlaceHolder;
        if (phSidebar != null)
            phSidebar.Visible = false;
    }
        
</script>
Mar 7, 2009 at 1:49 AM
Thank you very much, I will give this a try and report back to you.
Mar 7, 2009 at 3:44 AM
Edited Mar 7, 2009 at 3:45 AM
I am having a problem with the .cs file, receiving error when I paste in the code. This is the original code.

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;

public partial class site : System.Web.UI.MasterPage
{
    protected void Page_PreRender(object sender, EventArgs e)
    {
        if (phSidebar.Visible)
            Form1.Attributes.Add("class", "body");
        else
            Form1.Attributes.Add("class", "body noSidebar");
            }



  protected void Page_Load(object sender, EventArgs e)
  {
        if (Page.User.Identity.IsAuthenticated)
        {
            aLogin.InnerText = Resources.labels.logoff;
            aLogin.HRef = BlogEngine.Core.Utils.RelativeWebRoot + "login.aspx?logoff";
        }
        else
        {
            aLogin.HRef = BlogEngine.Core.Utils.RelativeWebRoot + "login.aspx";
            aLogin.InnerText = Resources.labels.login;
        }
  }

  public string MenuClass(string menuName)
  {
      if (Request.RawUrl.Contains(menuName))
          return "class=\"menu-hover\"";
      else
          return string.Empty;
  }



}

Mar 7, 2009 at 4:21 AM
Sorry I messed up, I had the wrong .cs file, works like a charm, thank you kindly for your help.
Feb 15, 2010 at 3:54 PM

Ben,

I am trying to get this to work with the Andreas-04-BE theme and am stuck on the master.cs file with this part, can you enlighten me?

protected void Page_PreRender(object sender, EventArgs e)
{
if (phSidebar.Visible)
Form1.Attributes.Add("class", "body");
else
Form1.Attributes.Add("class", "body noSidebar");
}

I can't seem to find the right code to put in place of form1

I thought container1024 would work but it doesn't.

 

Thank you for your help.

This is the master file:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="site.master.cs" Inherits="themes_andreas04_site" %>
<%@ Import Namespace="BlogEngine.Core" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head id="Head1" runat="server" profile="http://gmpg.org/xfn/11">

<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="your description goes here" />
<meta name="keywords" content="your,keywords,goes,here" />
<meta name="author" content="Your Name" />
<link type="text/css" rel="stylesheet" href="style04.css" media="screen,projection" />
<link rel="shortcut icon" href="~/pics/favicon.ico" type="image/x-icon"/>

<title>SAHC</title>
<style type="text/css">
.style1
{
width: 222px;
height: 53px;
}
</style>
</head>

<body>

<div id="container1024"> <!-- use id="container800" or id="container1024" to make layout fixed-width -->


<div id="sitetitle">
<h1><a href="<%=Utils.AbsoluteWebRoot %>"><%=BlogSettings.Instance.Name %></a></h1>
<h2><%=BlogSettings.Instance.Description %>!</h2>
&nbsp;</div>


<div id="menu">
<img align="left" alt="Southern Arizona Hiking Club" src="/Images/sahclogo2.gif" />
<a href="<%=Utils.AbsoluteWebRoot %>"><%=Resources.labels.home %></a><a href="<%=Utils.AbsoluteWebRoot %>archive.aspx"><%=Resources.labels.archive %></a>
<a href="<%=Utils.AbsoluteWebRoot %>contact.aspx"><%=Resources.labels.contact %></a>
<a href="http://www.sahcinfo.org/SAHC_Gallery_10/index.html">Gallery</a>
<a href="http://sahcinfo.org/members/sahc_pdf1.aspx">E Bulletins</a>&nbsp;
<a runat="server" id="aLogin" />

</div>
<form runat="Server">
<div id="content">
<div id="left">
<div>
<blog:SearchOnSearch ID="SearchOnSearch1" runat="server" MaxResults="3" Headline="You searched for" Text="Here are some results for the search term on this website" />
<asp:ContentPlaceHolder ID="cphBody" runat="server" />
</div>

</div>
<asp:PlaceHolder ID="phSidebar" runat="server">
<div id="right">
<blog:WidgetZone runat="server" ID="rightzone" />
</div>
</asp:PlaceHolder>

<div id="footer">
© 2010 <a href="<%=Utils.AbsoluteWebRoot %>"><%=BlogSettings.Instance.Name %></a> |
Design by Stylish <a href="http://www.stylishtemplate.com/">Website Templates</a> |
Adapted by <a href="http://blogs.gusac.net">Gusac.Net</a> |
BE <%=BlogSettings.Instance.Version() %> |
Website designed and maintained by <a href="http://www.seniorgeekpc.com/">Senior Geek Computer Services</a>
</div>
</div>
</form>
</div>
</body>
</html>

 

 

Coordinator
Feb 15, 2010 at 11:44 PM

The sidebar is being correctly hidden, but the CSS isn't working right?  The CSS you will want to put into the CSS file for this case would be:

form.noSidebar #container1024{
    width:100%;
}

This would make it so the DIV with the ID of container1024 will use up 100% of the available width (you can change to a fixed pixel amount if you want).  This rule will kick in when the "noSidebar" CSS class is assigned to the <form> which will occur when the sidebar is hidden.

Feb 15, 2010 at 11:56 PM
Edited Feb 16, 2010 at 12:15 AM

Thank you Ben, I made this change to the CSS but the page is still not using 100% do I still need some code in the master.cs file?

http://sahcinfo.org/membership_applicationcopy.aspx

http://sahcinfo.org/current_hikes.aspx

Coordinator
Feb 16, 2010 at 12:18 AM
Edited Feb 16, 2010 at 12:19 AM

Thanks for the URL -- that helps.

I see ... it's not container1024 that we want to adjust the width for.  It's the div with an ID of "left".  Currently the LEFT div is 68% width.  We'll want to change that to 100% or maybe 99% (100% should work).  This CSS should be in your CSS file.

form.noSidebar #left{
    width:100%;
}

Also, on that page, the <form> tag doesn't have the "noSidebar" CSS class.  Do you have the rest of the code in place?  The PreRender code in the master page, and the Page_Load handler in the membership_applicationcopy.aspx (and current_hikes.aspx) files?

The <form> tag looks like this:

<form name="aspnetForm" method="post" action="/membership_applicationcopy.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="aspnetForm" class="body">

The "class" attribute should be "body noSidebar" instead of just "body".

Feb 16, 2010 at 12:58 PM

Thanks Ben,

I may  be a bit confused with this.

In the site.master I have this:

<asp:PlaceHolder ID="phSidebar" runat="server">
<div id="sidebar">
<blog:WidgetZone runat="server" ID="rightzone" />
</div>
</asp:PlaceHolder>

I am not clear on what goes in the site.master.cs:

In the css I have this:

form.noSidebar #left{width:100%;
}

In the pages I wish to be no sidebar I have this in the code behind file:

protected void Page_Load(object sender, EventArgs e)
{
PlaceHolder phSidebar = Master.FindControl("phSidebar") as PlaceHolder;
if (phSidebar != null)
phSidebar.Visible = false;
}

 

I am not sure where to put this:

<form name="aspnetForm" method="post" action="/membership_applicationcopy.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="aspnetForm">

or this statement

The "class" attribute should be "body noSidebar" instead of just "body".

Thank you for your patience with me and thanks for our continued support.

 

 

 

Coordinator
Feb 16, 2010 at 7:30 PM

In this theme, the sidebar is in the DIV with the ID of "right".  So the placeholder should be wrapped around that DIV.  Actually the content you pasted yesterday looks right.  Like this:

<asp:PlaceHolder ID="phSidebar" runat="server">
<div id="right">
<blog:WidgetZone runat="server" ID="rightzone" />
</div>
</asp:PlaceHolder>

On those 2 pages you have, the sidebar is correctly removed.  So I think you have the above markup correct.

The missing part is in the master page code behind (site.master.cs), this part should be there:

protected void Page_PreRender(object sender, EventArgs e)
{
    if (phSidebar.Visible)
        Form1.Attributes.Add("class", "body");
    else
        Form1.Attributes.Add("class", "body noSidebar");
}

This is one of the last pieces of code that runs.  It will look to see if the sidebar placeholder is visible.  If not, then it will add the class "body noSidebar" to the <form> tag.

Feb 16, 2010 at 7:53 PM

Thanks for the reply Ben.

When I place this in the site.master.cs

protected void Page_PreRender(object sender, EventArgs e)
{
if (phSidebar.Visible)
Form1.Attributes.Add("class", "body");
else
Form1.Attributes.Add("class", "body noSidebar");
}

I get this:

The name 'Form1' does not exist in this context.

Coordinator
Feb 16, 2010 at 8:30 PM

Okay... in the site.master file, you have a <form> tag.  Add an explicit ID to that form ... as shown below:

<form ID="Form1" runat="Server">

Feb 17, 2010 at 12:25 AM

Thank you very much for your help and patience with this Ben, I appreciate it very much, everything is working great now.

Coordinator
Feb 17, 2010 at 1:40 AM

No problem.  I see the pages are working now -- glad to see it!