pag 中各属性的介绍(官网.c#)

来源:互联网 发布:手机进程清理软件 编辑:程序博客网 时间:2024/05/17 08:45
Page 类
表示从 ASP.NET Web 应用程序的宿主服务器请求的 .aspx 文件(又称为 Web 窗体页)。

命名空间: System.Web.UI
程序集: System.Web(在 system.web.dll 中)

语法语法
Visual Basic(声明)
Public Class Page    Inherits TemplateControl    Implements IHttpHandler
Visual Basic (用法)
Dim instance As Page
C#
public class Page : TemplateControl, IHttpHandler
C++
public ref class Page : public TemplateControl, IHttpHandler
J#
public class Page extends TemplateControl implements IHttpHandler
JScript
public class Page extends TemplateControl implements IHttpHandler
XAML
不适用。
备注备注

Page 类与扩展名为 .aspx 的文件相关联。这些文件在运行时被编译为 Page 对象,并被缓存在服务器内存中。

如果要使用代码隐藏技术创建 Web 窗体页,请从该类派生。应用程序快速开发 (RAD) 设计器(如 Microsoft Visual Studio)自动使用此模型创建 Web 窗体页。

Page 对象充当页中所有服务器控件(实现

Page 类是一个用作 Web 应用程序的用户界面的控件,因此应对这样的类进行仔细检查以确保遵循编写安全代码和保证应用程序安全的最佳做法。有关这些主题的常规信息,请参见 Web 应用程序安全威胁概述、安全策略最佳实施策略 和 安全性的基础概念。有关更具体的信息,请参见 保证标准控件的安全、如何:显示安全错误信息、如何:通过对字符串应用 HTML 编码在 Web 应用程序中防止脚本侵入 和 验证控件介绍。

Topic Location How to: Determine How ASP.NET Web Pages Were Invoked 在 Visual Studio 中构建 ASP .NET Web 应用程序 How to: Locate the Web Forms Controls on a Page by Walking the Controls Collection 在 Visual Studio 中构建 ASP .NET Web 应用程序 如何:确定调用 ASP.NET 网页的方式 生成 ASP .NET Web 应用程序 如何:通过遍历控件集合定位页上的 Web 窗体控件 生成 ASP .NET Web 应用程序 演练:为移动设备创建网页 在 Visual Studio 中构建 ASP .NET Web 应用程序
INamingContainer 接口的控件或实现此接口的控件的子控件除外)的命名容器。
示例示例

下面的代码示例演示如何在代码隐藏页模型中使用 Page 类。注意,代码隐藏源文件声明了一个从基页类继承的分部类。基页类可以是 Page,也可以是从 Page 派生的其他类。另外请注意,分部类允许代码隐藏文件使用页中定义的控件,而无需将其定义为字段成员。

Visual Basic
Imports SystemPartial Class MyCodeBehindVB    Inherits System.Web.UI.Page    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load        ' Place page-specific code here.    End Sub    ' Define a handler for the button click.    Protected Sub SubmitBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyButton.Click        MySpan.InnerHtml = "Hello, " + MyTextBox.Text + "."    End SubEnd Class
C#
复制代码
using System;public partial class MyCodeBehindCS : System.Web.UI.Page{         protected void Page_Load(object sender, EventArgs e)    {        // Place page-specific code here.    }    // Define a handler for the button click.    protected void SubmitBtn_Click(object sender, EventArgs e)    {            MySpan.InnerHtml = "Hello, " + MyTextBox.Text + ".";    }}

下面的代码示例演示与前面的代码隐藏源文件对应的 .aspx 文件。

安全说明安全注意:

此示例有一个接受用户输入的文本框,这是一个潜在的安全威胁。默认情况下,ASP.NET 网页验证用户输入是否不包含脚本或 HTML 元素。有关更多信息,请参见脚本侵入概述。

Visual Basic
复制代码
<%@ Page Language="VB" CodeFile="pageexample.aspx.vb" Inherits="MyCodeBehindVB" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html  ><head runat="server">    <title>Page Class Example</title></head><body>    <form id="form1" runat="server">    <div>       <table>          <tr>            <td> Name: </td>            <td> <asp:textbox id="MyTextBox" runat="server"/> </td>          </tr>          <tr>             <td></td>             <td><asp:button id="MyButton" text="Click Here" onclick="SubmitBtn_Click" runat="server"/></td>          </tr>          <tr>             <td></td>             <td><span id="MySpan" runat="server" /></td>          </tr>       </table>             </div>    </form></body></html>
C#
复制代码
<%@ Page Language="C#" CodeFile="pageexample.aspx.cs" Inherits="MyCodeBehindCS" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html  ><head runat="server">    <title>Page Class Example</title></head><body>    <form id="form1" runat="server">    <div>       <table>          <tr>            <td> Name: </td>            <td> <asp:textbox id="MyTextBox" runat="server"/> </td>          </tr>          <tr>             <td></td>             <td><asp:button id="MyButton" text="Click Here" onclick="SubmitBtn_Click" runat="server"/></td>          </tr>          <tr>             <td></td>             <td><span id="MySpan" runat="server" /></td>          </tr>       </table>         </div>    </form></body></html>

必须使用 @ Page 指令并使用 InheritsCodeFile 属性将代码隐藏文件链接至 .aspx 文件。在此示例中,Inherits 属性指示 MyCodeBehind 类,CodeFile 属性指示包含该类的语言特定的文件的路径。

下面的代码示例演示单文件页模型以及如何访问 Page 的 IsPostBack 属性和 Response 属性。

Visual Basic
复制代码
<%@ Page Language="VB" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)    Dim sb As New StringBuilder()        If (Page.IsPostBack) Then            sb.Append("You posted back to the page.<br />")        End If        sb.Append("The host address is " + Page.Request.UserHostAddress + ".<br />")    sb.Append("The page title is """ + Page.Header.Title + """.")        PageMessage.Text = sb.ToString()      End Sub  </script><html  ><head runat="server">    <title>Page Class Example</title></head><body>    <form id="form1"           runat="server">    <div>    <asp:Label id="PageMessage"                runat="server"/>    <br /> <br />    <asp:Button id="PageButton"                Text="PostBack"                runat="server" />        </div>    </form></body></html>
C#
复制代码
<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">  protected void Page_Load(object sender, EventArgs e)  {    StringBuilder sb = new StringBuilder();        if (Page.IsPostBack)      sb.Append("You posted back to the page.<br />");    sb.Append("The host address is " + Page.Request.UserHostAddress + ".<br />");    sb.Append("The page title is /"" + Page.Header.Title + "/".");    PageMessage.Text = sb.ToString();  }</script><html  ><head runat="server">    <title>Page Class Example</title></head><body>    <form id="form1"           runat="server">    <div>    <asp:Label id="PageMessage"                runat="server"/>    <br /> <br />    <asp:Button id="PageButton"                Text="PostBack"                runat="server" />    </div>    </form></body></html>
复制代码
.NET Framework 安全性.NET Framework 安全性
  •  
  • AspNetHostingPermission  用于在宿主环境中进行操作。要求值:InheritanceDemand;权限值:Minimal
AspNetHostingPermission  用于在宿主环境中进行操作。要求值:LinkDemand;权限值:Minimal。
继承层次结构继承层次结构
System.Object
   System.Web.UI.Control
     System.Web.UI.TemplateControl
      System.Web.UI.Page
         System.Web.UI.MobileControls.MobilePage
线程安全线程安全
此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。 平台平台

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

 

Windows Vista、Microsoft Windows XP SP2 和 Windows Server 2003 SP1 支持 Microsoft .NET Framework 3.0。

版本信息版本信息

.NET Framework

受以下版本支持:3.0、2.0、1.1、1.0