Hello
I'm working on the Try-it-out on p.284 ("Creating Smarter User Controls").
I followed the directions to the letter, and VWD refuses to recognize DisplayDirection on Banner.ascx.cs The error keeps popping up saying "A switch expression or case label must be a bool, char, string, integral, enum, or corresponding nullable type". I really a appreciate your help
First, my Direction class:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for Direction
/// </summary>
public class Direction
{
public enum Direction
{
Horizontal,
Vertical
}
}
Second, here is my code-behind for my Banner control:
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
{
public Direction DisplayDirection { get; set; }
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;
}
}
}
Next, the markup for the banner control:
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" AlternateText="This is a sample banner"
ImageUrl="~/Images/Banner120x240.gif" />
</a>
</asp:Panel>
<asp:Panel ID="HorizontalPanel" runat="server">
<a href="http://p2p.wrox.com" target="_blank">
<asp:Image ID="Image2" runat="server" AlternateText="This is a sample banner"
ImageUrl="~/Images/Banner468x60.gif" />
</a>
</asp:Panel>
And this is the master page's 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">Header Goes Here</a></div>
</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 Theme<br />
<asp:DropDownList ID="ThemeList" runat="server" AutoPostBack="True"
Height="16px" Width="140px">
<asp:ListItem>Monochrome</asp:ListItem>
<asp:ListItem>DarkGrey</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<Wrox:Banner ID="Banner1" runat="server" />
<br />
<br />
<br />
<br />
</div>
<div id="Footer">Footer Goes Here</div>
</form>
</body>
</html>