Unit-4 - ASP - Net and Web Development - Part-3
Unit-4 - ASP - Net and Web Development - Part-3
Header Hi
I am Krunal
Footer
Master Page
Characteristics :
• Extension of MasterPage is ‘.master’.
• Master Page also has a codebehind file.
• We cannot run MasterPage directly.
• It allows you to centralize the common functionality of your pages so that
you can make updates in just one place.
• One website can contain many MasterPages. But at a time one webpage
contain only one MasterPage.
• You can create multiple master pages to define different layouts for parts of
your site, and a different set of content pages for each master page.
• It’s possible to display consistent look for FY student and another look for
SY and TY.
• They make it easily to create one set of controls and code and apply the
results to a set of pages.
Master Page
• For example, you can use controls on the MasterPage to create a menu that
applies to all pages.
• MasterPage should contain at least one ContentPlaceHolder control.
• Runtime we can change the MasterPage.
• The declaration for a MasterPage :
• <%@ Master Language=“C#” AutoEventWireup=“true”
CodeFile=“MasterPage.master.cs” Inherits=“MasterPage” %>
• Runtime MasterPage and Normalpage (ContentPage) will merge.
• We can access any of the control of MasterPage from Contentpage.
• When user associates a master page with a content page, the content page
automatically includes the title attributes.
ContentPlaceHolder
• When a new Masterpage is added a ContentPlaceHolder control is present.
• Content place holders are used to allocate places on the MasterPage that
will be changed on the content pages.
• Content placeholder is a control in MasterPage. The content from the
content page appears in the area made by content place holder control.
• There are two ContentPlaceHolder on any MasterPage.
1. In the Head section
2. In between <form></form>
• The actual Webpage contents will be pasted in the form section.
• You can have multiple ContentPlaceHolders on the same page.
• Example :
<asp:ContentPlaceHolder id =“ContentPlaceHolder1” runat=“server”>
</asp:ContentPlaceHolder>
Content Pages
• The content pages contains the content you want to display.
• For example, Home.aspx, Aboutus.aspx, Contactus.aspx, CheckMail.aspx,
ContentPages.aspx etc are Content Pages.
• We define the content for the master page’s placeholder controls by
creating individual content pages, which are ASP.NET pages that are
bound to a specific master pages.
• When users request the content pages, they merge with the MasterPage to
produce output that combines the layout of the MasterPage with the
content from the content page.
• <%@ Master Language = “C#” AutoEventWireup = “true”
CodeFile=“Stu.master.cs” Inherits= “MasterPage” %>
Content Pages
Resulting
Page
Content Pages
Run-time Behaviour of Master Page :
1. Users request a page by typing the URL of the content page.
2. ASP.NET fetches the page.
3. When the page is fetched, the @Page directive is read. If the directive
references a master page, the master page is read as well. If this is the first
time the pages have been requested, both pages are compiled.
4. ASP.NET merges the content into the content placeholders on the
MasterPage.
5. The Masterpage with the updates content is merged into the control tree
of the content page.
6. ASP.NET renders results to the browsers.
Nested Master Page
• We have looked at how one can create a single Master Page and base a
content page on the Master Page.
• They give you the power to customize your web pages but keeping the
same overall look of the website as well.
• When one master page references another as its master, it is said to be a
nested master page.
Header Menu Hi
I am krunal
Footer
Footer
Nested Master Page
• For example, you can create one Master page for the entire web site and
then nest Master Pages below the site Master Page for individual sections.
• Master pages can be nested, with one master page referencing another as
its master.
• A number of nested masters can be componentized into a single master.
• There is no architectural limitation to the number of child masters that can
be created.
• The depth of nesting also does not impact on performing significantly.
• Just like the parent master page, child masters have the extension .master
too.
• It contains all the controls that are mapped to content place holders on the
parent master page.
• The layout is similar to that of a content page in this respect.
• However, child masters also have content place holders of their own to
display content of its child pages.
Theme
• Themes are an extension of another idea, like Master Page. Theme are
different than Master Pages.
• A Master page enables user to share content across multiple pages in a
website.
• A Theme, on the other hand, enables you to control the appearance of the
content.
• In www.yahoo.com , the theme concept is used.
• A theme is a collection of property settings that allow you to define the
look of pages in a web application, across an entire web application, or
across all web applications on a server.
• Themes can be thought of as a container where you store your style sheets,
images, skin files, etc..
• A theme folder can contain a variety of different types of files.
• Only one theme can be applied to each page.
Theme
• Applying CSS to HTML seems to be simple and easy, but applying the
same to ASP.NET server controls can be confusing, because it is up to the
developer to know which HTML tags are rendered by the control and how
they are rendered.
Skin File
• For example, if you create a default skin for a TextBox control, the control
skin applies to all TextBox controls on pages that use the theme.
Skin File
2. Named Skins :
• It is a control skin with a SkinID property set.
• Named skins do not automatically apply to controls by type.
• The SkinId should be uniquely defined because duplicate SkinId’s per
control type are not allowed in the same theme.
• Example :
<asp:GridView runat=“server” SkinId=“gridviewSkin”
BackColor=“White” >
</asp:GridView>
Style Sheet
• A Cascading Style Sheet (CSS) may be added to a Theme by planning it
under the named Theme subdirectory.
• When you put a .css file in the theme directory, the style sheet is applied
automatically as part of the theme.
• Extension of the CSS file is .css.
Demo of Named Skin
<%@ Page Language = “C#” AutoEventWireup = “true” CodeFile =
“Default4.aspx.cs” Inherits = “Default4” Theme = “Summer” %>
• Code :
<asp:GridView id=“GridView1” runat=“server”>
</asp:GridView>
GridView Control
• Properties :
Property Description
AllowPaging True/False. Indicate whether the control should
support paging.
AllowSorting True/False. Indicate whether the control should
support sorting.
SortExpression Gets the current sort expression that determines the
order of the row.
SortDirection Gets the sorting direction of the column sorted
currently.
DataSource Gets/Sets the data source object that contains the data
to populate the control.
GridView Control
• Events :
Event Description
RowCommand Fires when a button is clicked on any row of GridView.
RowCreated Fires when a new row is created in GridView.
RowDataBound Fires when row is bound to the data in GridView.
RowDeleting , RowDeleted Both events fires when Delete button of a row is
clicked. They fire before and after GridView handles
deleting operation of the row respectively.
RowEditing Fires when an Edit button of a row is clicked but before
the GridView handles the Edit operation.
SelectedIndexChanged Fires when an item is selected in the GridView, after
the selection is complete.
Demo of GridView with stu Table
• Step – 1 : Stu Table Design View
Name DataType
Rno Int
Sname Varchar (20)
Sphoto Varchar (50)
Gender Bit
DOB Date
SqlDataSource – SqlDataSource1
Column0 Column1 Column2
Abc Abc Abc
Abc Abc Abc
Demo of GridView with stu Table
• Step – 3 : Configure SqlDataSource1 with Stu Table
<Columns>
<asp:CommandField ShowSelectButton = “True” />
Demo of GridView with stu Table
<asp:BoundField DataField = “Rno” HeaderText = “Rno” ReadOnly=“True”
SortExpression = “Rno”>
</asp:GridView>
Question
1. Explain the concept of master pages in ASP.NET with example. (Summer
2016 , Summer 2014 , Winter 2013)
2. Explain data binding with GridView control related to ADO.NET
Technology. (Summer 2016)
3. Write a note on Master Page in ASP.NET (Winter 2015 , Summer 2015)
4. Explain master page and theme of ASP.NET. (Winter 2014)
5. What is Theme? Create skin file to format various controls and give code
to apply theme in ASP.NET webpage. (Summer 2014, Summer 2018)
6. How can you implement Master page in Web Base? Explain clearly with
example. (Winter 2016)
7. Explain the concept of master pages in ASP.NET with example. (Summer
2017 , Winter 2018)
8. Differentiate between Master Page and Theme Page in ASP.NET. (Winter
2017)
Question
1. Write a program which gets data from ‘uses’ table and shows on console
in tabular format. (Summer 2015)
2. Give demo of Master page – 5 pages
3. Give demo of Theme.
4. Create one emp table which contains column Sid, Sname, Gender, Std
and display student records in GridView with select, update and delete.
5. Create one emp table which contains column Sid, Sname, Gender, Std
and display student records in GridView and Create one dropdown which
contains DeptName on selected DeptName display record in GridView.
You
a n k
T h