Thursday, June 27, 2013

Theme In C# asp.net


  1. Open Visual Studio File -->New--> Website (Create Website)
  2. Add App_Code Folder
  3. Inside App_Code Folder Add Class (ThemeClass.cs) 
  4. Add master Page
  5. Then Add Default .aspx Use Master Page
ThemeClass.Cs

public class themeclass : System.Web.UI.Page
{
   
    protected void Page_PreInit(object sender, EventArgs e)
    {
        if (Session["Theme"] != null)
        {
            Page.Theme = Session["Theme"].ToString();
        }
    }
   
}

I have Used inherited Class By Page



Default.aspx

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

 <div>
        <table class="tablecss" align="center" width="30%">
            <tr>
                <td colspan="2" align="center">
                    <h3>
                        Registration Form</h3>
                </td>
            </tr>
            <tr>
                <td align="right">
                    UserName:
                </td>
                <td>
                    <asp:TextBox ID="txtUser" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td align="right">
                    Email:
                </td>
                <td>
                    <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td align="right">
                    Date of Birth:
                </td>
                <td>
                    <asp:TextBox ID="txtDOB" runat="server"></asp:TextBox>
                </td>
            </tr>           
            <tr>
                <td align="right">
                    Address:
                </td>
                <td>
                    <asp:TextBox ID="txtAddress" runat="server" Columns="17" Rows="8" TextMode="MultiLine"></asp:TextBox>
                </td>
            </tr>
        </table>
    </div>
</asp:Content>



Default.CS

public partial class _Default : themeclass
{
    protected void Page_Load(object sender, EventArgs e)
    {
       

    }
}

System.Web.UI.Page is replaced by Class Name

MasterPage

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!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>Untitled Page</title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div id="header" runat="server" style="align: center">
            <asp:DropDownList ID="ddlchangecolor"  runat="server" OnSelectedIndexChanged="ddlchangecolor_SelectedIndexChanged"
                OnTextChanged="ddlchangecolor_TextChanged">
                <asp:ListItem Text="White" Value="White"></asp:ListItem>
                <asp:ListItem Text="Blue" Value="Blue"></asp:ListItem>
                <asp:ListItem Text="Red" Value="Red"></asp:ListItem>
                <asp:ListItem Text="Purple" Value="Purple"></asp:ListItem>
            </asp:DropDownList>
            <asp:Button ID="btnBlue" runat="server" Text="Change Theme" BackColor="Blue" Font-Bold="true"
                OnClick="btnBlue_Click" />
        </div>
        <%--   <asp:ScriptManager ID="ScriptManager1" runat="server" />--%>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        </asp:ContentPlaceHolder>
        <div id="footer" runat="server">
        </div>
    </div>
    </form>
</body>
</html>


MasterPage.CS
using System;

public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void ddlchangecolor_SelectedIndexChanged(object sender, EventArgs e)
    {      
    }
    protected void btnBlue_Click(object sender, EventArgs e)
    {
        Session["Theme"] = ddlchangecolor.SelectedItem.Value.ToString().Trim();
     
        Server.Transfer(Request.FilePath);
    }
    protected void ddlchangecolor_TextChanged(object sender, EventArgs e)
    {
      
    }
}

 In The App_Theme Folder 
Add Skin With Blue, Purple, Red , White
Add CSS With Every Skin
Blue.CSS Under Blue Folder
body
{
    background-color:Blue;
}


Purple.CSS Under PurpleFolder
body
{
    background-color:
Purple;
}




Red.CSS Under Red Folder
body
{
    background-color:
Red;
}


White.CSS Under White Folder
body
{
    background-color:
White;
}


Happy Coding



No comments:

Post a Comment