How to use Master Page in asp.net

Leave a Comment
Aim: Create A master page and content Page Application for the University which enables user to see the faculty list according to department.


MASTER PAGE:

<%@ 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">
    <asp:Table ID="Table1" Width="50%" runat="server">
        <asp:TableRow BorderWidth="1px" Width="100%">
            <asp:TableCell Font-Size="Large" BorderWidth="1PX"  HorizontalAlign="Center" >
                      <h1> D.D.UNIVERSITY</h1>
            </asp:TableCell>  
        </asp:TableRow>     
         <asp:TableRow>
            <asp:TableCell>
            <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">          
           </asp:ContentPlaceHolder>           
            </asp:TableCell>  
        </asp:TableRow>
      
    </asp:Table>
      
    </form>
</body>
</html>
  



CONTENT PAGE:

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" Title="Untitled Page" %>
  <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
            <asp:Table ID="Table1" width="100%" runat="server" BorderWidth="2px" BorderColor="Black">
          <asp:TableRow BorderWidth="1PX" >
            <asp:TableCell BorderWidth="1px"  Width="50%" >                            <asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_click" AutoPostBack ="true" >
                         
                </asp:DropDownList>                    
            </asp:TableCell>
            <asp:TableCell BorderWidth="1px" Width="50%">            <asp:DropDownList ID="DropDownList2" runat="server">
          
                </asp:DropDownList>                   
             </asp:TableCell>   
        </asp:TableRow>
 </asp:Table>
  </asp:Content>


CONTENT PAGE CS FILE
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
 public partial class Default3 : System.Web.UI.Page
{    protected void Page_Load(object sender, EventArgs e)    {        if (!IsPostBack)        {            DropDownList1.Items.Clear();            DropDownList1.Items.Add("Informatio Tech");            DropDownList1.Items.Add("Computer eng.");            DropDownList1.Items.Add("electronic commu");        }    }    protected void DropDownList1_click(object sender, EventArgs e)    {
        switch (DropDownList1.SelectedItem.Text)        {            case "Informatio Tech": DropDownList2.Items.Clear();                                    DropDownList2.Items.Add("R.S.chhajed");                                    DropDownList2.Items.Add("M.M.Goswami");                                    DropDownList2.Items.Add("Vipul dabhi");                                    break;            case "Computer eng.": DropDownList2.Items.Clear();                                  DropDownList2.Items.Add("C.K.B");                                  DropDownList2.Items.Add("P.H.D");                                  DropDownList2.Items.Add("NAINISH");                                  break;            case "electronic commu": DropDownList2.Items.Clear();                                   DropDownList2.Items.Add("N.J.KOTHARI");                                      DropDownList2.Items.Add("H.B.P");                                       DropDownList2.Items.Add("BHAVIN");                                  break;        }       
    }}
 output:



Just try to implement it and if you don't understand just leave comment i will explain you ....Have a Good day!!!

0 comments:

Post a Comment