Download presentation
Presentation is loading. Please wait.
1
State management & Master Pages in asp.net
Created By: Asst. Prof. Ashish Shah State management & Master Pages in asp.net
2
Asp.net includes followng features
Created By: Asst. Prof. Ashish Shah Asp.net includes followng features Client side : it is done using . View state . Cookies . Hidden fields . Query String(URL) 2) Server Side : it is done using . Session state . Application state . Caching
3
Created By: Asst. Prof. Ashish Shah
View state It is about the state of the page and all its controls. It automatically maintains the post by asp.net framework. When page is sent back to the client for o/p , the changes in the properties of the page and its controls are determined and stored in the value of a hidden input field named _VIEWSTATE. When the page is again post back the _VIEWSTATE field is sent back to the server.
4
View state we can enabled/disabled it for
Created By: Asst. Prof. Ashish Shah View state we can enabled/disabled it for Entire application : by setting view state property in <pages> section of web.config file. Page : this can be done by setting EnableViewState property. Page Language=“C#” EnableViewState=“true” %> 3) Control : This can be done by setting the control’s EnableViewState property.
5
Session State Modes Following are available modes:
Created By: Asst. Prof. Ashish Shah Session State Modes Following are available modes: InProc : It stores session state in memory on the web server. This is the default. StateServer : It stores session state in separate process called as asp.net state service. SQL Server : It stores the session state in SQL Server database. Custom: It is done by custom storage provider Off mode: It disables Session State mode.
6
Cookies To create it the syntax is as follows.
Created By: Asst. Prof. Ashish Shah Cookies To create it the syntax is as follows. HttpCookie studentcookie = new HttpCookie(“cook”); studentcookie.Value = text1.Text; studentcookie.Expires= DateTime.Now.AddHours(1); Response.Cookies.Add(studentcookie); . To Read the values from cookie: string studname=Request.Cookies[“studentcookie”].Value;
7
Created By: Asst. Prof. Ashish Shah
QueryString It is a essential part of passing data from one web page to other. QueryString is a simply appending the data to the end of the URL; User can view the values of it without using any special oprations like “ViewSource”. Eg. &name=tyit Note: ? Is a separator between the url and QueryString variables.
8
QueryString Advantages: Very easy to use. Disadvantages:
Created By: Asst. Prof. Ashish Shah QueryString Advantages: Very easy to use. Disadvantages: If number of parameters increases then it becomes difficult to maintain the code using it. It can’t be used to send space character or “&”. It is visible in url of browser so secured information cant be send using it.
9
Created By: Asst. Prof. Ashish Shah
MASTER PAGES It is used to make a consistent layout for an application, using which we can maintain common layout and functionality of whole application’s web page which is known as Content Pages. Master page has extension .master (infact it is a .aspx page) having directive as follows. Master Language=“C#” CodeFile=“MasterPage.master.cs” Inherits=master_MasterPage” %>
10
Created By: Asst. Prof. Ashish Shah
MASTER PAGES Every master page should include at least one ContentPlaceHolder control as follows. <asp:ContentPlaceHolder id=“CPH1” runat=“server” /> The Content page is a standard aspx page in which MasterPageFile Attribute should be added to the page directive for binding the content page to the master page. The content page cant include the common tags as <body>,<head> etc. We can desing content page just like any other aspx page by adding static text and server controls. Page Language=“C#” MasterPageFile=“MasterPage.master” CodeFile=“Default2.aspx.cs” Inherits=“Default2” Title=“Masterpagedemo” %> Inside the content pages, by default, content server control is get added. While designing the content page you have to add controls to the content server control. For eg. <asp:Content ID=“CONTENT1” ContentPlaceHolderID=“CPH1” runat=“server” /> The attribute of ContentPlaceHolderID is very imp. As it decides what content will be bound tp which ContentPlaceHolder on the master page. It is a way to decide the location of where the contents is to be displayed.
11
Created By: Asst. Prof. Ashish Shah
Navigation Controls Navigation for asp.net pages manages movement and dataprocessing between aspx pages. Web appn. are having multiple pages interconnected wth each other in some fashion, so proper navigation system must be there which can help end user to work successfully within an appn. Following are the three navigation controls SiteMapPath Menu TreeView
12
Created By: Asst. Prof. Ashish Shah
SiteMapPath All navigation controls uses an XML-based file which is known as site map. Sitemaps are used to describe the logical structure of web application. It is used to define the layout of all pages in web application and how they relate to each other. Whenever we want to add or remove pages to sitemap, there by managing navigation of website efficiently. Sitemap files are defined with sitemap extension.
13
SiteMapPath The root node of sitemap file is <sitemap> element.
Created By: Asst. Prof. Ashish Shah SiteMapPath The root node of sitemap file is <sitemap> element. Only one <sitemap> element can exist in the sitemap file. With in this element there is a <siteMapNode> element. This is generally the start page of the application, it has following attributes: Title: It provides a textual description of the link. Description: it is used for ToolTip of the link. URL: It gives the location of the valid physical file.
14
Created By: Asst. Prof. Ashish Shah
Example of sitemap Home .I.T. DEPT FYIT SYIT To describe following logical structure the code of sitemap file is as follows.
15
Created By: Asst. Prof. Ashish Shah
Example of sitemap <sitemap xmlns=“ “> <siteMapNode url=“Default.aspx” title=“home” description=“go to homepage”/> <siteMapNode url=“It.aspx” title=“I.T. DEPT” description=“it dept information”> <siteMapNode url=“fyIt.aspx” title=“FYIT” description=“FYIT information” /> <siteMapNode url=“syIt.aspx” title=“SYIT” description=“SYIT information” /> </siteMapNode>
16
Created By: Asst. Prof. Ashish Shah
MenuControl It is used to display menu in a web page and used in combination with SiteMapDataSource control for navigating a website. It displays to types of menu, static and dynamic. Static menu is always displayed , by default only one menu item at the root levels is displayed. Dynamic menu gets displyed only when the user moves the mouse pointer over the parent menu that contains a dynamic submenu.
17
Created By: Asst. Prof. Ashish Shah
MenuControl To create menu control in master page , so it can be displayed in all subsequnet page, we have to write a following code below. <asp:Menu ID=“Menu1” runat=“server” DataSourceID=“SiteMapDataSource1”/> After saving the changes in master page all content page will get reflection automatically.
18
Created By: Asst. Prof. Ashish Shah
TreeView Control A TreeView Control displays a Hierarchical list of data. When TreeView is displayed for the first time, it displays all its node. We can control it by setting ExpandDepth property. To create TreeView control in master page , so it can be displayed in all subsequent page, we have to write a following code below. <asp:TreeView ID=“TV1” runat=“server” />
19
TreeView Control Some Properties of it Properties Description
Created By: Asst. Prof. Ashish Shah TreeView Control Some Properties of it Properties Description DataSourceID To specify datasource to be used using sitemap file as datasource ShowLines To specify the lines to connect the individual items in a tree CssClass To specify CSS class attribute for the control ExpandDepth To specify level at which items in the tree are expanded.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.