Exforsys

ASP.NET 2.0

  1. Getting started with ASP.NET 2.0
  2. .NET Framework Fundamentals
  3. Microsoft.NET Framework Tools
  4. Application Development in .NET
  5. What's New in the .NET Framework 2.0 ?
  6. Introduction to Visual Studio.NET
  7. Installing Visual Studio.NET 2005
  8. Working with Visual Studio.NET Web Applications
  9. Whats New in ASP.NET 2.0
  10. Creating an ASP.NET Application
  11. ASP.NET Code Directory
  12. ASP.NET Page Object Model
  13. ASP.NET Server Controls
  14. ASP.NET Working With Master Pages
  15. ASP.NET Creating Content for Master Page
  16. ASP.NET Referencing Master Page Members
  17. ASP.NET Changing Master Pages Dynamically
  18. ASP.NET Creating Nested Master Pages
  19. ASP.NET Working with Web Parts
  20. ASP.NET Using Web Parts and Controls in Web Pages
  21. ASP.NET Web Pages and Layout
  22. ASP.NET - Adding Web Parts at Run Time
  23. ASP.NET Personalization: User Profiles and Themes
  24. ASP.NET Data Access features
  25. ASP.NET State Management
  26. ASP.NET Customizing the Session State Mechanism
  27. ASP.NET State Management And Caching
  28. ASP.NET Security
  29. Forms Authentication in ASP.NET
  30. ASP.NET Managing Membership and Roles
  31. ASP.NET Configuring Page-Level Caching
  32. ASP.NET Setting Application-Level Caching
  33. ASP.NET Data Source Object Model
  34. ASP.NET SqlDataSource Control
  35. ASP.NET Data Bound Controls
  36. ASP.NET GridView Control
  37. ASP.NET GridView Filtering
  38. ASP.NET Adding Sorting and Paging in GridView
  39. ASP.NET DataBound Controls - Details View
  40. ASP.NET Using a Grid to Display Detail Information
  41. ASP.NET Displaying Master-Detail Data on the Same Page
  42. Displaying Master-Detail Data on Separate Pages in ASP.NET
  43. ASP.NET Creating Web Wizards
  44. ASP.NET : Dynamic Image control
  45. ASP.NET Advanced Site Functionality

Home arrow Technical Training arrow ASP.NET 2.0

ASP.NET Advanced Site Functionality

Author : Exforsys Inc.     Published on: 16th Sep 2005    |   Last Updated on: 16th Feb 2007

ASP.NET Advanced Site Functionality

In this tutorial you will learn advanced site functionality, Enhanced Page Framework, To create the Web.Sitemap file, Tracking Traffic with Site Counters and Going Mobile.

Ads

Enhanced Page Framework

The advanced functionalities offered by ASP.NET include site navigation and site counters. The built in navigation has three components:

1. Site Structure which is a programming interface that lists the hierarchical structure of the Website. The site map object exposes this interface using the components provided by the Site Map Provider. The default data store is usually a root level xml file named app.sitemap.

2. Site Navigation is a control that names each node defined in the site map and associates it with a URL.

3. Site Structure Display is a component that renders the site navigation user interface in an intelligent fashion and maps user friendly URLs to appropriate .aspx files.

The Site Map is a container for the hierarchical collection of nodes representing pages in an application. The default representation of a site map is Web.sitemap. This is an xml file.

To create the Web.Sitemap file:

1. Right click on the Website root folder and select Add New item…

2. Select a XmlFile and name it Web.sitemap

3. Open the file and add the following code to it.

Sample Code
  1. <siteMap>
  2. <siteMapNode title="Home" description="Home" url="~/default.aspx">
  3. <siteMapNode title="Courses" description="Our Courses"
  4.  url="~/Courses.aspx">
  5. <siteMapNode title="Web Application Development" description="Web Application Courses" url="~/webapp.aspx" />
  6. <siteMapNode title="Windows Application Development" description="Windows Application Courses"
  7. url="~/Winapp.aspx" />
  8. </siteMapNode>
  9. <siteMapNode title="Certifications" description="Certifications we offer" url="~/Certifications.aspx">
  10. <siteMapNode title="Training" description="Training classes"
  11.  url="~/Training.aspx" />
  12. <siteMapNode title="Microsoft" description="Microsoft certifications" url="~/Microsoft.aspx" />
  13. <siteMapNode title="Oracle" description="Oracle Certifications"
  14.  url="~/Oracle.aspx" />
  15. </siteMapNode>
  16. </siteMapNode>
  17. </siteMap>
Copyright exforsys.com


4. Open the Default.aspx file and enter the following code to the page.

Sample Code
  1. <%@ Page Language="C#" CodeFile="Default.aspx.cs" Inherits="Default_aspx" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" target="_blank" rel="nofollow">
  4. <script runat="server">
  5.     void Page_Load(object sender, EventArgs e)
  6.     {
  7.         InitSiteMap()
  8.     }
  9.     void InitSiteMap()
  10.     {
  11.         caption.Text = SiteMap.RootNode.Title
  12.         foreach (SiteMapNode node in SiteMap.RootNode.ChildNodes)
  13.         {
  14.             ListItem LI = new ListItem()
  15.             LI.Text = node.Title
  16.             LI.Value = node.Url
  17.             MyLinks.Items.Add(LI)
  18.         }
  19.     }</script>
  20. <html xmlns="http://www.w3.org/1999/xhtml >
  21. <head runat="server">
  22.     <title>Site Map</title>
  23. </head>
  24. <body>
  25.     <form id="form1" runat="server">
  26.     <asp:Panel Id= "MyPanel" runat="server"
  27.     backColor="#FFFFC0"
  28.     width="100%">
  29.     <h1> <asp:Label runat="server" ID="caption" valign="top" BackColor="#FFFFC0">ExForSys Site Map</asp:Label></h1>
  30.     </asp:Panel>
  31.     <table width="100%"><tr><td style="width:200" bgcolor="lightcyan" valign="top">
  32.     <asp:BulletedList runat="server" ID="MyLinks" DisplayMode="HyperLink"  />
  33.     </td><td style="Width:10" bgcolor="lightcyan"></td><td valign="top"> Content of the Page</td></tr></table>
  34.     <asp:SiteMapDataSource runat="server" ID="MySiteMap" />
  35.     <asp:TreeView runat="server" DataSourceID="MySiteMap">
  36.     <RootNodeStyle Font-Bold="true" />
  37.     <ParentNodeStyle Font-Bold="true" />
  38.     <NodeStyle Font-Size="0.8em" />
  39.     <DataBindings>
  40.     <asp:TreeNodeBinding NavigateUrlField="url" TextField="title" /></DataBindings>
  41.     </asp:TreeView>
  42.     <asp:Menu runat="server" DataSourceID="MySiteMap" />
  43.     </form>
  44. </body>
  45. </html>
Copyright exforsys.com


5. Press F5 to execute the program. The output will look as under:

Let us examine what we have done in the above code. We have used a Panel control to define a header and put a label in it and we have added a BulletedList control to display the contents of the SiteMap.

Click here to view sample code

Then we have used a TreeView control to display the same information in a different format.

Click here to view sample code

Finally we have used a Menu control to display the same information.

< asp:Menu runat="server" DataSourceID="ExForSysSiteMap" / >

Another type of control that can be used to display the same information is the SiteMapPath control. This control displays a navigation path and shows the current user the place he is in and displays links to the Home page. The entire control can be deployed and bound to a data source without writing a single line of code. The SiteMapPath is customizable. The links will appear as: Home > Courses > Web Application Development. The user can navigate back and forth at higher or lower levels of the hierarchy using the SiteMapPath controls navigation features.

Tracking Traffic with Site Counters

Another advanced control provided by ASP.NET 2.0 for site enhancement is the Site Counter. This is extremely useful in monitoring visitor activity. The two types of site activity normally performed by visitors are Impression and ClickThrough. Impression is a viewing of some specific content while ClickThrough is a user’s click to see a specific content. The site counters provide means to track these activities and collects the read and write related activities to a database via an ad hoc provider. Counter data can be collected using page view counters and server counters such as Hyperlink and AdRotator.

For counters to work, the site counter service must be enabled in the configuration file in the site counters section. A database must be set up before they are used and finally the provider must be set up and connected to the related database using the Web Administration tool.

A hyperlink control configured to track clicks would be coded as under:

< asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="http://www.exforsys.com" Text="Visit us at ExForSys for the best tutorials" counterclicks="true" counterName="Exforsys.com" >< / asp:HyperLink >

Apart from accessing the counters declaratively it is possible to access the counters programmatically also. The Static members of the Site counter class can be used for reading and writing data in the site counters. The GetRows method returns a DataSet object filled with the site counter table.

Site counter providers include the AccessDataSource provider and the SQLDataSource Provider. ADO.NET classes are used to read and write onto the tables. Site counter tables are named aspnet_SiteCounters by default.

Going Mobile

ASP.NET 1.x used the Microsoft Mobile Toolkit to code for mobile devices. In ASP.NET 2.0 all controls have a mobile interface. The infrastructure of the server control are now built on a control adapter architecture. There is an adapater for each device and the number of adapters can be added. Since the controls are derived from the adapters no special action is required to be performed. The adapter renders the control intelligently to the device.

The following code is a sample of the code for a nokia device.

< asp:Label id="MyLabel" runat="server"
Text="Welcome ExForSys.com"
Nokia:Text="Time to upgrade your Nokia phone!"
cssClass="StandardStyleClass"
Nokia:cssClass="SpecialNokiaStyleClass" / >

Ads

The Mechanisms help developers override the built in rendering for mobile devices and provide automatic support with standard controls. However there are some controls which are specifically built for mobile devices. For instance the PhoneLink and Pager controls are exclusively for mobile devices.

It is clear that the direction of development of Web application development is the creation of a seamless, supportive, codeless environment that helps rapid application development and ease of deployment.

 
This tutorial is part of a ASP.NET 2.0 tutorial series. Read it from the beginning and learn yourself.

ASP.NET 2.0

  1. Getting started with ASP.NET 2.0
  2. .NET Framework Fundamentals
  3. Microsoft.NET Framework Tools
  4. Application Development in .NET
  5. What's New in the .NET Framework 2.0 ?
  6. Introduction to Visual Studio.NET
  7. Installing Visual Studio.NET 2005
  8. Working with Visual Studio.NET Web Applications
  9. Whats New in ASP.NET 2.0
  10. Creating an ASP.NET Application
  11. ASP.NET Code Directory
  12. ASP.NET Page Object Model
  13. ASP.NET Server Controls
  14. ASP.NET Working With Master Pages
  15. ASP.NET Creating Content for Master Page
  16. ASP.NET Referencing Master Page Members
  17. ASP.NET Changing Master Pages Dynamically
  18. ASP.NET Creating Nested Master Pages
  19. ASP.NET Working with Web Parts
  20. ASP.NET Using Web Parts and Controls in Web Pages
  21. ASP.NET Web Pages and Layout
  22. ASP.NET - Adding Web Parts at Run Time
  23. ASP.NET Personalization: User Profiles and Themes
  24. ASP.NET Data Access features
  25. ASP.NET State Management
  26. ASP.NET Customizing the Session State Mechanism
  27. ASP.NET State Management And Caching
  28. ASP.NET Security
  29. Forms Authentication in ASP.NET
  30. ASP.NET Managing Membership and Roles
  31. ASP.NET Configuring Page-Level Caching
  32. ASP.NET Setting Application-Level Caching
  33. ASP.NET Data Source Object Model
  34. ASP.NET SqlDataSource Control
  35. ASP.NET Data Bound Controls
  36. ASP.NET GridView Control
  37. ASP.NET GridView Filtering
  38. ASP.NET Adding Sorting and Paging in GridView
  39. ASP.NET DataBound Controls - Details View
  40. ASP.NET Using a Grid to Display Detail Information
  41. ASP.NET Displaying Master-Detail Data on the Same Page
  42. Displaying Master-Detail Data on Separate Pages in ASP.NET
  43. ASP.NET Creating Web Wizards
  44. ASP.NET : Dynamic Image control
  45. ASP.NET Advanced Site Functionality
 

Comments