Introduction
Themes are also a new feature of ASP.NET that helps maintain a consistent look and feel across all or several pages of our web site . It is a collection of files that define the looks of a page. It can include skin files, CSS files & images . Themes are of two types:
Global Theme
To set the theme for the entire website you can set the theme in the web.config of the website. Open the web.config file and locate the <pages> element and add the theme attribute to it:
<pages theme="Theme1">
....
....
</pages>
Step 10 : Press F5 keys to run the application.
Themes are also a new feature of ASP.NET that helps maintain a consistent look and feel across all or several pages of our web site . It is a collection of files that define the looks of a page. It can include skin files, CSS files & images . Themes are of two types:
Page Theme
The Theme attribute is added to the page directive of the page.
The Theme attribute is added to the page directive of the page.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"Inherits="Default" Theme="Theme1"%>
Global Theme
To set the theme for the entire website you can set the theme in the web.config of the website. Open the web.config file and locate the <pages> element and add the theme attribute to it:
<pages theme="Theme1">
....
....
</pages>
Let's create a theme application with the help of the following steps:
Step 1 : Open Microsoft Visual Studio 2010.
Step 2 : Select File->New->Web Site.
Step 3 : Select ASP.NET Web Site and then click Ok.
Step 4 : Now right-click in the application name in the Solution Explorer window and select Add
ASP.NET Folder->Theme from the context menu.
Step 5 : Right-click on the Theme1 folder and select the Add New Item option.
Step 6 : Select the Stylesheet and name it as Theme1.css.
Step 7 : Write the following code Inside Theme1.css.
Step 2 : Select File->New->Web Site.
Step 3 : Select ASP.NET Web Site and then click Ok.
Step 4 : Now right-click in the application name in the Solution Explorer window and select Add
ASP.NET Folder->Theme from the context menu.
Step 5 : Right-click on the Theme1 folder and select the Add New Item option.
Step 6 : Select the Stylesheet and name it as Theme1.css.
Step 7 : Write the following code Inside Theme1.css.
body{
background-color:Red;
}
Step 8 : Write the following code for Default.aspx page.background-color:Red;
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" Theme="Theme1" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<asp:Label ID="Label2" runat="server" Font-Bold="False"
Font-Names="Comic Sans MS" Font-Underline="True"
Text="THEME EXAMPLE"></asp:Label>
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="enter the data in the text box">
</asp:Label>
<br />
<br />
<asp:TextBox ID="TextBox1" runat="server" Height="42px" Width="237px"> </asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Click Button"
BorderColor="#996633" BorderStyle="Solid" BorderWidth="5px" Height="60px" />
<br />
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="Select the Theme"></asp:Label>
<br />
<br />
<br />
<br />
<br />
<br />
</div>
</form>
</body>
</html>
Step 9 : Now write the following code for the default.aspx.cs file:Inherits="_Default" Theme="Theme1" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<asp:Label ID="Label2" runat="server" Font-Bold="False"
Font-Names="Comic Sans MS" Font-Underline="True"
Text="THEME EXAMPLE"></asp:Label>
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="enter the data in the text box">
</asp:Label>
<br />
<br />
<asp:TextBox ID="TextBox1" runat="server" Height="42px" Width="237px"> </asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Click Button"
BorderColor="#996633" BorderStyle="Solid" BorderWidth="5px" Height="60px" />
<br />
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="Select the Theme"></asp:Label>
<br />
<br />
<br />
<br />
<br />
<br />
</div>
</form>
</body>
</html>
public partial class default : System.Web.UI.Page{
static string themeValue;
public ThemeTest()
{
this.PreInit+=new EventHandler(Page_PreInit);
}
private void Page_PreInit(object sender, EventArgs e)
{
Page.Theme = themeValue;
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
themeValue = ListBox1.SelectedItem.Value;
Response.Redirect(Request.Url.ToString());
}
}
No comments:
Post a Comment