Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 7th, 2011, 04:33 PM
Registered User
 
Join Date: Jul 2011
Location: Mount Jackson, VA
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Exclamation HorizontalPanel remains visible = false?

When I "View in Browser" the HorizontalPanel is hidden but, the vertical panel works fine.

I verified that I am in fact hitting the appropriate case in the switch statement that sets visible to true for the HorizontalPanel. But, when I load the page and view source, all of the code is greyed out (using Firebug) which indicates it isn't visible.

Direction.cs
Code:
public enum Direction
{
    Horizontal,
    Vertical
}
Banner.ascx
Code:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Banner.ascx.cs" Inherits="Controls_Banner" %>
<asp:Panel ID="VerticalPanel" runat="server">
    <a href="http://p2p.wrox.com" target="_blank">
        <asp:Image ID="Image1" runat="server" ImageUrl="~/Images/Banner120x240.gif" AlternateText="This is a sample banner." />
    </a>
</asp:Panel>
<asp:Panel ID="HorizontalPanel" runat="server">
    <a href="http://p2p.wrox.com" target="_blank">
        <asp:Image ID="Image2" runat="server" ImageUrl="~/Images/Banner468x60.gif" AlternateText="This is a sample banner." />
    </a>
</asp:Panel>
Banner.ascx.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Controls_Banner : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        HorizontalPanel.Visible = false;
        VerticalPanel.Visible = false;
        switch (DisplayDirection)
        {
            case Direction.Horizontal:
                HorizontalPanel.Visible = true;
                break;
            case Direction.Vertical:
                VerticalPanel.Visible = true;
                break;
        }
    }
    public Direction DisplayDirection { get; set; }
}
Frontend.master
Code:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Frontend.master.cs" Inherits="MasterPages_Frontend" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
        <div id="PageWrapper">
            <div id="Header"><a href="~/" runat="server"></a></div>
            <div id="MenuWrapper">
                <asp:Menu ID="Menu1" runat="server" CssClass="MainMenu" 
                    DataSourceID="SiteMapDataSource1" Orientation="Horizontal" 
                    StaticEnableDefaultPopOutImage="False"></asp:Menu>
                <asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1" 
                    ShowExpandCollapse="False">
                    <LevelStyles>
                        <asp:TreeNodeStyle CssClass="FirstLevelMenuItems" />
                    </LevelStyles>
                </asp:TreeView>
                <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" 
                    ShowStartingNode="False" />
            </div>
            <div id="MainContent">
                <asp:SiteMapPath ID="SiteMapPath1" runat="server"></asp:SiteMapPath><br /><br />
                <asp:ContentPlaceHolder ID="cpMainContent" runat="server"></asp:ContentPlaceHolder>
            </div>
            <div id="Sidebar">
                Select a Theme:<br />
                <asp:DropDownList ID="ThemeList" runat="server" AutoPostBack="True" 
                    onselectedindexchanged="ThemeList_SelectedIndexChanged">
                    <asp:ListItem>DarkGrey</asp:ListItem>
                    <asp:ListItem>Monochrome</asp:ListItem>
                </asp:DropDownList>
                <br />
                <br />
                <Wrox:Banner ID="Banner1" runat="server" DisplayDirection="Vertical" />
            </div>
            <div id="Footer">Footer Goes Here</div>
        </div>
    </form>
</body>
</html>
Frontend.master.cs
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class MasterPages_Frontend : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string selectedTheme = Page.Theme;
            HttpCookie preferredTheme = Request.Cookies.Get("PreferredTheme");
            if (preferredTheme != null)
            {
                selectedTheme = preferredTheme.Value;
            }
            if (!string.IsNullOrEmpty(selectedTheme) && ThemeList.Items.FindByValue(selectedTheme) != null)
            {
                ThemeList.Items.FindByValue(selectedTheme).Selected = true;
            }
        }
        switch (Page.Theme.ToLower())
        {
            case "darkgrey":
                Menu1.Visible = false;
                TreeView1.Visible = true;
                break;
            default:
                Menu1.Visible = true;
                TreeView1.Visible = false;
                break;
        }
    }
    protected void ThemeList_SelectedIndexChanged(object sender, EventArgs e)
    {
        HttpCookie preferredTheme = new HttpCookie("PreferredTheme");
        preferredTheme.Expires = DateTime.Now.AddMonths(3);
        preferredTheme.Value = ThemeList.SelectedValue;
        Response.Cookies.Add(preferredTheme);
        Response.Redirect(Request.Url.ToString());
    }
}
web.config
Code:
<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>

    <system.web>
        <pages theme="Monochrome">
            <controls>
                <add tagPrefix="Wrox" tagName="Banner" src="~/Controls/Banner.ascx" />
            </controls>
        </pages>
        <compilation debug="false" targetFramework="4.0" />
    </system.web>

</configuration>
Any help would be greatly appreciated.
  #2 (permalink)  
Old July 7th, 2011, 05:47 PM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

I am not sure I understand the question. You say it's hitting the setting for the Horizontal panel, but the code is setting it to the Vertical panel:

Code:
 
<Wrox:Banner ID="Banner1" runat="server" DisplayDirection="Vertical" />
Also, I am not sure what you mean with this:
Quote:
But, when I load the page and view source, all of the code is greyed out (using Firebug) which indicates it isn't visible.
What do you mean with greyed out? Also, since you're setting the visibility server side, the HTML shouldn't even make it to the browser. In the browser's HTML you should only ever see one of the two panels.

Can you elaborate?

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #3 (permalink)  
Old July 8th, 2011, 08:24 AM
Registered User
 
Join Date: Jul 2011
Location: Mount Jackson, VA
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thank you for the quick reply Imar. When I set the DisplayDirection to "Horizontal" I do not get the horizontal bar. Even though all of the HTML shows up in the source view on the browser.

Here is a copy / paste of the 'view source' from the browser. I notice a CSS class gets assigned to the Horizontal image but, not the vertical. Thanks again for any help.

DisplayDirection set to Horizontal (doesn't show anything on screen, but appears in page source)
Code:
<div id="Banner1_HorizontalPanel">
    <a id="Banner1_HorizontalLink" target="_blank" href="http://p2p.wrox.com">
        <img id="Banner1_Image2" class=" wecnztkxpwdkbzxbczrc" alt="This is a sample banner" src="Images/Banner468x60.gif">
    </a>
</div>
DisplayDirection set to Vertical (works fine, displays both on screen and in page source)
Code:
<div id="Banner1_VerticalPanel">
    <a id="Banner1_VerticalLink" target="_blank" href="http://p2p.wrox.com">
        <img id="Banner1_Image1" alt="This is a sample banner" src="Images/Banner120x240.gif">
    </a>
</div>
  #4 (permalink)  
Old July 8th, 2011, 08:29 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Ah, I see. I *think* you have some ad blocking software on your machine that hides ads for you. The format of the banner is in a typical ad size, so the software blocks it by adding some dynamic CSS class to it.....

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
MAllen22842 (July 8th, 2011)
  #5 (permalink)  
Old July 8th, 2011, 08:36 AM
Registered User
 
Join Date: Jul 2011
Location: Mount Jackson, VA
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Absolutely correct! My ad-blocker in the browser was blocking the image. Thank you again Imar.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Me.Visible = false not working Daj Access VBA 6 January 27th, 2009 12:17 PM
certain columns of a row in datagrid visible false nanu yaru VS.NET 2002/2003 0 March 31st, 2008 08:27 AM
Non-displacement of controls when visible="false" rsearing ASP.NET 2.0 Professional 2 January 26th, 2007 06:27 PM
Can't see data from boundcolumn visible=false ipaine ASP.NET 1.x and 2.0 Application Design 1 June 20th, 2006 02:54 PM
set rpttext box visible false myth12345 VB How-To 0 March 4th, 2005 11:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.