Delete the sidebar on a page.

Apr 17, 2012 at 2:30 PM
Edited Apr 17, 2012 at 2:34 PM

I would like to delete the sidebar for this page:

http://www.tftm.keeponhiking.com/ditd_reg1.aspx

 

I am using the TitaniumX theme.

 

This is not working in the .cs

 

 {
        PlaceHolder phSidebar = Master.FindControl("phSidebar") as PlaceHolder;
        if (phSidebar != null)
            phSidebar.Visible = false;
    }
Apr 17, 2012 at 4:24 PM

Hi Jerry, 

If you only want to manipulate the style for this one page, which doesn't appear to be a BE generated page, you could alter the CSS.

Try adding this before the content on your "ditd_reg1.aspx" page.

<script runat="server">
protected override void OnLoad(EventArgs e)
{
	base.OnLoad(e);
    	string styleInfo = "<style type=\"text/css\"> #content {width:auto; float:none;} #sidepanel {display:none;}</style>";
    	var newStyles = new LiteralControl() {Text = styleInfo };
    	this.Header.Controls.Add(newStyles);
        
}
</script>
Might do the trick for a one-off.

Apr 17, 2012 at 6:19 PM

Thank you very much Andy, it works great!

Apr 17, 2012 at 6:32 PM
Edited Apr 17, 2012 at 6:42 PM

Good, 

Probably best to alter that code slightly to ensure the styles get added only once.

<script runat="server">

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);    

    if (this.Header.FindControl("newStyles") == null)
    {
        string styleInfo = "<style type=\"text/css\"> #content {width:auto; float:none;} #sidepanel {display:none;}</style>";
        var newStyles = new LiteralControl() { ID = "newStyles", Text = styleInfo };
        this.Header.Controls.Add(newStyles);    
    }   
        
}

</script>
 

If you decide to change the theme, this will of course break, but you might be able to alter the above to suit.

Cheers for now.

Apr 17, 2012 at 6:48 PM

Thanks, can this code be used on a BE generated page also?

Apr 17, 2012 at 7:33 PM

This code should work on a page by page basis for custom pages you add inheriting "BlogBasePage", but for BE generated pages you would need a different approach.

The way I do it for BE pages is to use page detection in the master.cs (not unlike the code snippet you have at the start of this thread).

If it's a BE page then alter the layout (giving a blanket layout change for all BE pages) and then add HTML to individual pages to structure as required.

The tinymce editor has a button that you can use to add code snippets (HTML templates), but does require configuring, alternatively just drop the code into the editor in HTML mode. I'm using BE pages exclusively and find this works well, have a look and click around.

If you want a hand setting that up, you're welcome.

Oct 2, 2012 at 11:33 PM

Andy,

What would I need to alter in this code to make it work with the Yoko theme?  Thank

<script runat="server">
protected override void OnLoad(EventArgs e)
{
	base.OnLoad(e);
    	string styleInfo = "<style type=\"text/css\"> #content {width:auto; float:none;} #sidepanel {display:none;}</style>";
    	var newStyles = new LiteralControl() {Text = styleInfo };
    	this.Header.Controls.Add(newStyles);
        
}
</script>
you for your time.

Oct 3, 2012 at 7:38 PM

Hi Jerry,

Been preoccupied with affairs of state and just switched the PC on, otherwise I'd have been a little snappier in replying.

I think I'd need to have a look at the page as a starting point, is it possible to give a link?

Is it just the odd page here and there that you want to change the layout?

In the meantime. I'll download the Yoko theme and have a poke around.

Might be tomorrow before I get a chance to get back to you though.

Oct 3, 2012 at 8:36 PM
Edited Oct 4, 2012 at 2:03 PM

Hi Andy,

I have 3 pages that I would like to remove the sidebar on, actually the sidebar is removed with the PortraitPress theme however I wish to change to the Yoko theme.  See here; http://blogengine.codeplex.com/discussions/397630

http://sahcinfo.org/members/ehike_schedule.aspx

http://sahcinfo.org/current_hikes.aspx

http://www.sahcinfo.org/scheduled_hikes.aspx

Oct 4, 2012 at 10:01 PM

Hi Jerry, 

Downloaded Yoko and had a quick look, it seems like the divs you would want to affect in this theme are named main and tertiary.

I haven't tested this, no time at the moment, so substituting the div names in the above code, you have:

<script runat="server">
protected override void OnLoad(EventArgs e)
{
	base.OnLoad(e);
    	string styleInfo = "<style type=\"text/css\"> #main {width:auto; float:none;} #tertiary {display:none;}</style>";
    	var newStyles = new LiteralControl() {Text = styleInfo };
    	this.Header.Controls.Add(newStyles);
        
}
</script>
Might be worth a try, haven't looked too close at other code that might have a bearing on this.