33
Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Embed Size (px)

Citation preview

Page 1: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Page 2: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

AgendaAgenda

Page 3: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Master PagesMaster Pages

Page 4: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Master Page BasicsMaster Page Basics

<%@ Master %>

<asp:ContentPlaceHolder ID="Main" RunAt="server" />

<%@ Master %>

<asp:ContentPlaceHolder ID="Main" RunAt="server" />

<%@ Page MasterPage- File="Site.master" %>

<asp:Content ContentPlaceHolderID= "Main" RunAt="server" />

</asp:Content>

<%@ Page MasterPage- File="Site.master" %>

<asp:Content ContentPlaceHolderID= "Main" RunAt="server" />

</asp:Content>

Page 5: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Defining a Master PageDefining a Master Page<%@ Master %>

<html> <body> <!-- Banner shown on all pages that use this master --> <table width="100%"> <tr> <td bgcolor="darkblue" align="center"> <span style="font-size: 36pt; color: white">ACME Inc.</span> </td> </tr> </table>

<!-- Placeholder for content below banner --> <asp:ContentPlaceHolder ID="Main" RunAt="server" /> </body></html>

Page 6: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Applying a Master PageApplying a Master Page<%@ Page MasterPageFile="~/Site.master" %>

<asp:Content ContentPlaceHolderID="Main" RunAt="server"> This content fills the place holder "Main" defined in the master page</asp:Content>

Page 7: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Applying a Master Page to a SiteApplying a Master Page to a Site<configuration> <system.web> <pages masterPageFile="~/Site.master" /> </system.web></configuration>

Page 8: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Applying a Master Page ProgrammaticallyApplying a Master Page Programmaticallyvoid Page_PreInit (Object sender, EventArgs e){ Page.MasterPageFile = "~/Site.master";}

Page 9: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Default ContentDefault Content

<%@ Master %> ...<asp:ContentPlaceHolder ID="Main" RunAt="server"> This is default content that will appear in the absence of a matching Content control in a content page<asp:ContentPlaceHolder>

Page 10: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

The Page.Master PropertyThe Page.Master Property

Page 11: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Accessing a Control in the Master Page (Weak Typing)Accessing a Control in the Master Page (Weak Typing)

((Label) Master.FindControl ("Title")).Text = "Orders";

<asp:Label ID="Title" RunAt="server" />

Page 12: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Accessing a Control in the Master Page (Strong Typing)Accessing a Control in the Master Page (Strong Typing)

Master.TitleText = "Orders";

<asp:Label ID="Title" RunAt="server" /> . . .<script language="C#" runat="server">public string TitleText{ get { return Title.Text; } set { Title.Text = value; }}</script>

Page 13: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Nesting Master PagesNesting Master Pages

<!-- Orders.Master --><%@ Master MasterPageFile="~/Site.Master" %>

<asp:Content ContentPlaceHolderID="..." RunAt="server"> <asp:ContentPlaceHolder ID="..." RunAt="server"> ... </asp:ContentPlaceHolder><asp:Content>

Page 14: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Master PagesMaster Pages

Page 15: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Themes and SkinsThemes and Skins

Page 16: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Applying a Theme to a PageApplying a Theme to a Page<%@ Page Theme="BasicBlue">

Page 17: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Applying a Theme to a SiteApplying a Theme to a Site<configuration> <system.web> <pages theme="BasicBlue" /> </system.web></configuration>

Page 18: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Applying a Theme ProgrammaticallyApplying a Theme Programmaticallyvoid Page_PreInit (Object sender, EventArgs e){ Page.Theme = "BasicBlue";}

Page 19: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Folder structureFolder structure

App_Themes

Shocking-Pink

Autumn-Leaves

SKIN

SKIN

SKIN

SKIN

vroot

Page 20: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Defining SkinsDefining Skins<!-- Default look for DropDownList controls --><asp:DropDownList runat="server" BackColor="hotpink" ForeColor="white" />

<!-- Default look for DataGrid controls --><asp:DataGrid runat="server" BackColor="#CCCCCC" BorderWidth="2pt" BorderStyle="Solid" BorderColor="#CCCCCC" GridLines="Vertical" HorizontalAlign="Left"> <HeaderStyle ForeColor="white" BackColor="hotpink" /> <ItemStyle ForeColor="black" BackColor="white" /> <AlternatingItemStyle BackColor="pink" ForeColor="black" /></asp:DataGrid>

...

Page 21: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Named SkinsNamed Skins

Page 22: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Defining Named SkinsDefining Named Skins<!-- Default look for DropDownList controls --><asp:DropDownList runat="server" BackColor="blue" ForeColor="white" SkinID="Blue" />

<!-- Default look for DataGrid conotrols --><asp:DataGrid runat="server" BackColor="#CCCCCC" BorderWidth="2pt" BorderStyle="Solid" BorderColor="#CCCCCC" GridLines="Vertical" HorizontalAlign="Left" SkinID="Blue"> <HeaderStyle ForeColor="white" BackColor="blue" /> <ItemStyle ForeColor="black" BackColor="white" /> <AlternatingItemStyle BackColor="lightblue" ForeColor="black" /></asp:DataGrid>

...

Page 23: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Using a Named SkinUsing a Named Skin<asp:DropDownList ID="Countries" SkinID="Blue" RunAt="server" />

Page 24: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

The EnableTheming PropertyThe EnableTheming Property

<asp:DropDownList ID="Countries" EnableTheming="false" RunAt="server" />

Page 25: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Themes and SkinsThemes and Skins

Page 26: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

New ControlsNew Controls

Category Controls

Data controls GridView and DetailsView

Data source controls SqlDataSource, ObjectDataSource, XmlDataSource, etc.

Login controls Login, CreateUserWizard, PasswordRecovery, etc.

Navigation controls Menu, TreeView, and SiteMapPath

Web Parts controls WebPartManager, WebPartZone, etc.

UI controls FileUpload, BulletedList, MultiView, Wizard, etc.

Page 27: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

UI ControlsUI ControlsName Description

BulletedList Renders bulleted lists of items

FileUpload UI for uploading files to Web servers

HiddenField Renders hidden fields

ImageMap Renders HTML image maps

MultiView Defines multiple views displayed one at a time

View Defines views in MultiView controls

Wizard Guides users through stepwise procedures

Substitution Designates non-cached regions of cached pages

Page 28: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

The ImageMap ControlThe ImageMap Control<asp:ImageMap ImageUrl="Shapes.jpg" OnClick="OnUpdate" RunAt="server"> <asp:CircleHotSpot X="50" Y="50" Radius="50" PostBackValue="Circle" AlternateText="Circle" HotSpotMode="Postback" RunAt="server" /> <asp:RectangleHotSpot Left="0" Top="100" Right="100" Bottom="200" PostBackValue="Rectangle" AlternateText="Rectangle" HotSpotMode="Postback" RunAt="server" /> <asp:PolygonHotSpot Coordinates="50, 200, 0, 300, 100, 300" PostBackValue="Triangle" AlternateText="Triangle" HotSpotMode="Postback" RunAt="server" /></asp:ImageMap> . . .<script language="C#" runat="server">void UpdateLabel (Object sender, ImageMapEventArgs e){ ...}</script>

Page 29: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

The FileUpload ControlThe FileUpload Control<asp:FileUpload ID="UploadControl" RunAt="server" /><asp:Button Text="Upload" OnClick="OnUpload" RunAt="server" /> . . .<script language="C#" runat="server">void OnUpload (Object sender, EventArgs e){ if (FileUploadControl.HasFile) { string name = UploadControl.PostedFile.FileName; // Path name Stream bits = UploadControl.PostedFile.InputStream; // Contents ... // Use the SaveAs method to persist to a local file FileInfo file = new FileInfo (UploadControl.PostedFile.FileName); UploadControl.SaveAs (Server.MapPath ("~/Uploads/" + file.Name); }}</script>

Page 30: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

The MultiView ControlThe MultiView Control<asp:MultiView ID="Main" ActiveViewIndex="0" RunAt="server"> <asp:View RunAt="server"> ... </asp:View> <asp:View RunAt="server"> ... </asp:View> <asp:View RunAt="server"> ... </asp:View></asp:MultiView> . . .void OnSwitchView (Object sender, EventArgs e){ Main.ActiveViewIndex = 1; // Switch views}

Page 31: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

Declarative View SwitchingDeclarative View Switching<asp:MultiView ID="Main" ActiveViewIndex="0" RunAt="server"> <asp:View RunAt="server"> ... <asp:Button CommandName="SwitchViewByIndex" CommandArgument="1" Text="Switch to view 2" RunAt="server" /> </asp:View> <asp:View RunAt="server"> ... <asp:Button CommandName="SwitchViewByIndex" CommandArgument="0" Text="Switch to view 1" RunAt="server" /> </asp:View></asp:MultiView>

Page 32: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0

ASP.NET 2.0 ControlsASP.NET 2.0 Controls

Page 33: Managing Look, Feel, and Layout with Visual Studio 2005 and ASP.NET 2.0