Page Directives and Page Properties in ASP.NET 4.0

By
Page Directive:-  ASP.NET Page Directives are instructions to specify optional setting, such as registering a custom control and page language. These settings are used to describe how ASP.NET web page(.aspx) or user control (ascx) page are processed by .NET Framework.
Page Directives can be placed anywhere in .aspx or .ascx file. But standard practice is to include them at the top of the file.
SYNTAX:-
<% @Page attributes="value"[attribute="value"......]%>
Page consists of following directives.
  1. @Page
  2. @Control
  3. @Import
  4. @Register
  5. @Assembly
  6. @Master
  7. @Previous page type
  8. @Master Type
  9. @Output Cache
  10. @Reference
ASP.NET 4.0, six new attributes for @page directive are included which are shown below:-
  • Client IDMode
  • Client Target
  • Meta Description
  • Meta keywords
  • Target Schema
  • View StateMode
There are some attribute is used in @Page Directive.
  • AutoEventWireup :- It is attribute of  @Page Directive. By default its value is 'True' that means event of page class will be bound automatically with event handlers but if it is 'false' then we need to bind event handler with page class event manually.
Example:- There are some steps to understand this concept
Step1:- Open your visual studio->go File->New website->select ASP.NET Empty website->Add  a Default.aspx page from the solution explore->drag and drop label control from Toolbox.
see it:->


Step2:- Open source from bottom of the page and change AutoEventWireup =false .
see it:-

Step3:- go Default,aspx.cs file and write the code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    public _Default()
    {
    Page.Load +=new EventHandler(Page_Load);
     
    }
    protected void Page_Load(object sender, EventArgs e)
    {
Label1.Text="page class Event is bound manually";
    } 
}

see it:->

Step4:- Run the application(press F5).
OUTPUT:->

Important Property of ASP.NET Page class:- There are two main property of  Page Class-
  1. IsPostBack 
  2. AutoPostBack
  • IsPostBack :->  When the page is loaded at first time this variable contain "False" value but some event fire on page and page is send to the server then comes back from the server this variable contains "true" value, so if we want to use some values only for the first time when page is loaded then we can use this property.
Example:->

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default2 : System.Web.UI.Page
{
Protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DropDownList1.Items.Add("RAM");
            DropDownList1.Items.Add("AJAY");
            DropDownList1.Items.Add("SOHAN");
            DropDownList1.Items.Add("VIJAY");
            DropDownList1.Items.Add("SANJAY");
        }
    }
    
}


Here i have Make this application on Default2.aspx, you can download whole code from the bottom:
  • AutoPostBack:-
Whenever we click on a button ,page automatically goes to the server for executing the handler ,but if we want to handle some other control event we need to set AutoPostBack property of Control is "True" Otherwise any event of that control will not handled.
see it
For More :-

  1.   Create a Setup File
  2.    Xml Application
  3.  Host ASP.NET Application on Server Free
  4.    Ado.Net Application
  5.    Print the Grid Data in Windows Forms Application

I hope this helpful for you.
To Get the Latest  Free Updates Subscribe
click below to download the whole application.
               DOWNLOAD
Powered by Blogger.