Asp .net

Document Sample
Asp .net Powered By Docstoc
 Web Application Model
 ASP.NET Page Elements
 ASP.NET State Management
 Master Pages
 Standard Controls
 Validation Controls
 Navigation Controls
 Login Controls
 Skins and Themes
 WebParts
             Web Application Model
• A client makes a page request by
   typing a web address into the
• An ASP.NET application is hosted on a
   web server, which is where C#
   executables reside.
• The infrastructure of the web finds
   the server where the web page
  On the server, web server software such as IIS intercepts the
    request, recognizes that it is for an ASP.NET web page and passes
    the request for ASP.NET for processing.
  ASP.NET the processes the web page, renders HTML and returns
    the rendered HTML to the browser.
      Elements of ASP.NET Page
 Every web form has an @Page directive which is
  on the top of the page.
 The Language attribute specifies the language
  being used, either C# or VB.
 CodeFile will be a page called a code-behind file,
  which enables handling events that occur on the
  web form.
 ASP.NET tags needs the runat=”server” attribute,
  which tells ASP.NET that it must process that tag
  on the server.
 All ASP.NET content that does have the
  runat=”server” tag will be rendered to HTML,
       What are Code-Behind Pages?

• Separation of code from content
   – Developers and UI designers can work independently

         Single file                                    Separate files

                                           <tags>                   code

         Form1.asp                        Form1.aspx              Form1.aspx.vb
                                                                or Form1.aspx.cs

Wednesday, February 06,   Sri Lanka Institute of Information
2008                             Technology - RAD
   Understanding How Code-Behind Pages Work

• Create separate files for user interface and
  interface logic
• Use @ Page directive to link the two files
• Pre-compile or JIT-compile

              Page1.aspx          public class WebForm1
    <% @ Page Language="c#"
                                       private void cmd1_Click()
    Codebehind="Page1.aspx.cs"            …
    Src = "Page1.aspx.cs" %>           }

ASP.NET state Management

   Life time of a web application

       Application object is created when first request by the
        user is made. Global across all web pages and all visitors.
       Application object is removed from the memory after
        inactivity or shut down by the server.
       A session object is created when first request by each
        user is made. Global across all pages for each individual
        web visitor.
       Session object is removed from the memory after
        inactivity by each individual web visitor.
  ASP.NET state management
 Since new instance of page is created for each request, state information cannot be maintained
  using the member variables. some special method has to be utilized to keep the state
  information of the Web-Application.
 There are three objects (member variables) in the web form which help to maintain state
  information. They are,
    Application
     ▪ Used to store application wide state information.
     ▪ These data can be accessed by any web form serving to any user.

    Session
     ▪ data consumes server resources (one copy per each user currently accessing the site) and
        reduces the scalability if the amount of information stored is high.

    ViewState

       ▪ Used to store state information of server controls of a web form.
       ▪ This information last for all post-backs of the same web form.
       ▪ These information does not require any server resource. However they are transmitted
         over the network in each request and response.
ASP.NET state management(Contd.)

The Application Object

• Application state variables are, in effect, global variables for each
  ASP.NET application.

• You can share values of these variables throughout that

• These variables are usually set in the Application_OnStart event
  and then accessed and modified in individual ASP.NET pages.
ASP.NET state management(Contd.)
• You can store values that need to be persisted for the duration of a
  user's session in session variables.

• These variables are unique to each user session and can be
  accessed in any ASP.NET page within an application. You can set
  and access session information from within an ASP.NET

    –   //Assign a value to the myvariable session variable.
    –   Session["myvariable"] = "somevalue";
    –   //Retrieve the value of the myvariable
    –   if (Session["myvariable"] != null) myString = (string)Session["myvariable"];

ASP.NET state management(Contd.)

The view state object
 View state is simply text. It is an aggregate of values of
  controls on a page. It's a string that contains values of page
  controls hashed and encoded in some manner.
 The view state contains no information about the server or
  the client. It only comprises information about the page itself
  and its controls. It lives along with the page in the user's
 As a rule, view state is stored right in the page and therefore it
  travels with it back and forth.
               Master Pages
• A master page defines the layout and
  appearance of all a Web site’s pages
• Creating a master page ensures that all the
  site’s pages have a consistent appearance
• A content page links to a master page, and
  displays the specific content of the Web form
• A content placeholder is a control that defines
  the area to place the controls that appear on
  the Web form.
                          Master Pages

Wednesday, February 06,    Sri Lanka Institute of Information
2008                              Technology - RAD
                 Skins and Themes
• Skin
   • Collection of property values that define the visual appearance
     of a specific type of control e.g. Button, Calendar, or GridView
   • Defined using standard ASP.NET control syntax but with a
     reduced property set
• Theme
   • Named collection of skins, images, and style sheets
   • Specified at the page level using @page directive to apply
     appropriate skins and styles to all controls on the page
   • Specified at site or folder level using Web.config to affect all
     pages within scope
   • Programmable at run time to offer enhanced customization and
     personalization capabilities
ASP.NET Controls
         Standard Web Controls

•   TextBox
                     Calendar
•   Button           Image
•   Label            ImageMap
•   CheckBox         MultiView
•   RadioButton      AdRotater
•   ListBox          FileUpload
•   HyperLink
•   Panel
• MultiView control acts as a container for a
  group of View controls
• View control is a container for a group of web
• MultiView control is used to display only a
  single group of controls at a time
• In Visual Studio, you can put View objects into
  a MultiView and put other web controls into
  View object.
• The basic idea is that you take an image an
  associate it with a "map" that specifies regions
  on the screen.

• Each region defines a hotspot on the screen,
  which acts like a hyperlink: it can navigate to
  another location on the Web.
• AdRotater is used to display advertisements
• An XML file is prepared that contains the
  advertisement information
• This XML file is shown as the
  AdvertisementFile property of the AdRotator
<?xml version="1.0" encoding="utf-8" ?>
  <AlternateText>Google Site1 Main</AlternateText>
  <AlternateText>Yahoo Site2 Main Page</AlternateText>
 The FileUpload control allows you to provide
  users with a way to send a file from their
  computer to the server.
 The control is useful for allowing users to upload
  pictures, text files, or other files.
 FileUpload1.HasFile property
    returns true if the user has selected a certain file (to be
     uploaded) using the FileUpload1 Control.
 FileUpload1.PostedFile.SaveAs(path & _
    It will upload a file to the passed physical path on the server.

• The Wizard control provides
  navigation through a series of
  steps that collect information
  incrementally from a user.

    The Wizard consists of: Collection of WizardSteps: Each
     WizardStep contains a discrete piece of content to be
     displayed to the user.
    Only one WizardStep will be displayed at a time.
                  Validation Controls
 Some common mistakes users
   Users might leave an important
    field blank
   Users might write a short-
    nonsense string to a required field
    (e.g. non-valid e-mail addresses)
   Users might make a typing error,
    or enter a non-numeric character
    to a numeric field
 Solution: Use Validation controls
                    Validation Controls
Validation Server Control    Description
CompareValidator             Compares the value of one input control to the
                                value of another input control or to a fixed
CustomValidator              Allows you to write a method to handle the
                                 validation of the value entered

RangeValidator               Checks that the user enters a value that falls
                                between two values
RegularExpressionValidator   Ensures that the value of an input control
                                matches a specified pattern

RequiredFieldValidator       Makes an input control a required field

ValidationSummary            Displays a report of all validation errors
                                 occurred in a Web page
           Navigation Controls

• Navigation UIs are tedious to implement
• New controls simplify site navigation
  – TreeView and Menu - Navigation User Interface (UI)
  – SiteMapDataSource - XML site maps
  – SiteMapPath
                      Site Maps
 A web site may contain several navigation points.
 A SiteMap provides a way of defining these
  navigation points and the relationship between
  these points
 Web site map
   A tree structure that shows the layout of the Web site forms
   To create the site map, define a siteMapNodes element for each
    tree node
   Allows users to navigate to any form by clicking on the
    associated node once bound to a bindable control
     Menu Control
Menus & trees
          ASP.NET Membership
 ASP.NET membership has been popular for the
  following reasons.
 Simplifies forms authentication
   Provides logic for validating user names and
    passwords, creating users, and more
   Manages data store for credentials, e-mail addresses,
    and other membership data
 Provider-based for flexible data storage
 Aspnet_regsql tool is used to Tool for creating
  database used by SqlMembershipProvider and
  other SQL Server providers
ASP.NET Web Administrative Tool
                   Login Controls
Name               Description

ChangePassword     UI for changing passwords

CreateUserWizard   UI for creating new user accounts

Login              UI for entering and validating user names and passwords

LoginName          Displays authenticated user names

LoginStatus        UI for logging in and logging out

LoginView          Displays different views based on login status and roles

PasswordRecovery   UI for recovering forgotten passwords
                 Login Controls
• Login Control
  – Standard UI for logging in users
  – Integrates with Membership service
     • Calls ValidateUser automatically
     • No-code validation and logins
  – Incorporates RequiredFieldValidators
                  Login Controls
 Login View
   Displays content differently to different users
    depending on:
    ▪ Whether user is authenticated
    ▪ If user is authenticated, the role memberships he or she is
   Template-driven
    ▪ <AnonymousTemplate>
    ▪ <LoggedInTemplate>
    ▪ <RoleGroups> and <ContentTemplate>
 Login Name
   Displays authenticated user names
 Websites and portals show a
  large amount of contents and
  content personalization.
 A web part can be defined as a
  window of information available
  to a user within a web page to
  support personalization.
 Users can add new web parts
  ,remove them , minimize them
  ,drag the parts on the page or
  change the appearance & etc.
 The WebPartManager is the central class of the
  Web Part Control Set, reponsable for managing
  and coordination all controls inside WebZones.
 The WebPartZone controls and provides an
  overall layout for the WebPart controls it
 The CatalogPart is the base class for catalog
  WebPart controls that present a list available
  web parts to users.
 CatalogZone is a container for CatalogPart
• The EditorZone exposes EditorPart classes
  which are used to edit the properties of a
  selected web part on the page.
• EditorZone is a container for the EditorPart
• The ConnectionZone allows to "connect" two
  web parts together in a provider-to-consumer
               WebPart Modes
 Modes are helpful in editing Web Parts, deleting
  the Web Parts or customizing Web Parts.
   Normal mode: End user cannot edit or move sections
    of page.
   Edit Mode: End user can edit Web Parts on the page
    including Web Parts title, color or even setting custom
   Design Mode: End user can rearrange the order of
    the pages Web Parts in a WebPartZone.
   Catalog Mode: End user enjoys the choice to add new
    Web Parts or add deleted Web Parts in any
    WebPartZone on the page.

Shared By: