Web Tutorials

Interview Q & A

Code Examples

Utility Tools

ASP.NET Page Directive

ASP.NET page defines is page-specific (.aspx file) attributes used by the ASP.NET page parser and compiler.

Syntax

<%@ Page attribute="value" [attribute="value"...] %>    

Page Directive Attributes

AttributesDescription
AutoEventWireupSpecifies the page event should autowired or not.
ClassNameSpecifies the class name that will be dynamically compiled when the page is requested.
CodeFileSpecifies the code-behind class for the current page.
CodeBehindSpecifies the path to the code-behind class for the current page.
CodeFileBaseClassSpecifies the type name of a base class for a page and its associated code-behind class
CompilerOptionsSpecifies compilation options for current page.
DescriptionSpecifies a text description of the master page.
DebugSpecifies page should be compiled with debug symbols.
LanguageSpecifies language being used when compiling inline code blocks.
InheritsSpecifies the base class for the page to inherit.
SrcSpecifies the source file that contains the implementation of the base class specified with Inherits.
MasterPageFileSpecifies the master page for the current page.
EnableSessionStateSpecifies the page should treat session data (true, false, readonly).
EnableViewStateSpecifies whether the page view state is maintained across page requests.
EnableThemingSpecifies the page will support themes for embedded controls.
ErrorPageSpecifies the error page URL to unhandled page exceptions.
ValidateRequestSpecifies whether the page request validation should occur.
CodePageSpecifies the code page value for the response.
ContentTypeSpecifies the HTTP content type of the page response.
TitleSpecifies the title of the page.
ResponseEncodingSpecifies the character encoding of the page.
BufferSpecifies HTTP response buffer of the page.

ASP.NET Page Directive Example C#

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="homePage.aspx.cs" 
Inherits="homePage" %>
<script runat="server">
private int minValue;
private int maxValue = 100;
private int currentNumber = 0;
public int MinValue
{
    get { return minValue; }
    set { minValue = value; }
}

public int MaxValue
{
    get { return maxValue; }
    set { maxValue = value; }
}

public int CurrentNumber
{
    get { return currentNumber; }
}

protected void Page_Load(Object sender, EventArgs e)
{
    if(IsPostBack)
    {
        currentNumber = Int32.Parse(ViewState["currentNumber"].ToString());
    }
    else
    {
        currentNumber = this.MinValue;
    }
    DisplayNumber();
}

protected void DisplayNumber()
{
    textNumber.Text = this.CurrentNumber.ToString();
    ViewState["currentNumber"] = this.CurrentNumber.ToString();
}

protected void buttonUp_Click(Object sender, EventArgs e)
{
    if(currentNumber == this.MaxValue)
    {
        currentNumber = this.MinValue;
    }
    else
    {
        currentNumber += 1;
    }
    DisplayNumber();
}

protected void buttonDown_Click(Object sender, EventArgs e)
{
    if(currentNumber == this.MinValue)
    {
        currentNumber = this.MaxValue;
    }
    else
    {
        currentNumber -= 1;
    }
    DisplayNumber();
}
</script>
<asp:TextBox ID="textNumber" runat="server" 
    ReadOnly="True" Width="32px" Enabled="False" />
<asp:Button Font-Bold="True" ID="buttonUp" runat="server"  
    Text="^" OnClick="buttonUp_Click" />
<asp:Button Font-Bold="True" ID="buttonDown" runat="server" 
    Text="v" OnClick="buttonDown_Click" />

ASP.NET Page Directive Example VB

<%@ Page Language="VB" AutoEventWireup="true" CodeFile="homePage.aspx.vb" 
Inherits="homePage" %>
<script runat="server">
    Private minValue As Integer = 0
    Private maxValue As Integer = 100
    Private currentNumber As Integer = 0
    Public Property MinValue() As Integer
        Get
            Return minValue
        End Get
        Set
			minValue = value
        End Set
    End Property
    
    Public Property MaxValue() As Integer
        Get
            Return maxValue
        End Get
        Set
           maxValue = value
        End Set
    End Property
    
    Public ReadOnly Property CurrentNumber() As Integer
        Get
            Return currentNumber
        End Get
    End Property
   
    Protected Sub Page_Load(ByVal sender As Object, _
            ByVal e As System.EventArgs)
        If IsPostBack Then
            currentNumber = CInt(ViewState("currentNumber"))
        Else
            currentNumber = Me.MinValue
        End If
        DisplayNumber()
    End Sub
    
    Protected Sub DisplayNumber()
        textNumber.Text = Me.CurrentNumber.ToString()
        ViewState("currentNumber") = Me.CurrentNumber.ToString()
    End Sub

    Protected Sub buttonUp_Click(ByVal sender As Object, _
            ByVal e As System.EventArgs)
        If currentNumber = Me.MaxValue Then
            currentNumber = Me.MinValue
        Else
            currentNumber += 1
        End If
        DisplayNumber()
    End Sub
    
    Protected Sub buttonDown_Click(ByVal sender As Object, _
            ByVal e As System.EventArgs)
        If currentNumber = Me.MinValue Then
            currentNumber = Me.MaxValue
        Else
            currentNumber -= 1
        End If
        DisplayNumber()
    End Sub
</script>
<asp:TextBox ID="textNumber" runat="server" 
    ReadOnly="True" Width="32px" Enabled="False" />
<asp:Button Font-Bold="True" ID="buttonUp" runat="server"  
    Text="^" OnClick="buttonUp_Click" />
<asp:Button Font-Bold="True" ID="buttonDown" runat="server" 
    Text="v" OnClick="buttonDown_Click" />

RequiredFieldValidator

RegularExpressionValidator

RangValidator

CompareValidator

CustomValidator

ValidationSummary