TextBox.OnPreRender(EventArgs) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
如果 AutoPostBack 為 true
,則在用戶端上呈現前,會先註冊產生回傳事件的用戶端指令碼。
protected:
override void OnPreRender(EventArgs ^ e);
protected public:
override void OnPreRender(EventArgs ^ e);
protected override void OnPreRender (EventArgs e);
protected internal override void OnPreRender (EventArgs e);
override this.OnPreRender : EventArgs -> unit
Protected Overrides Sub OnPreRender (e As EventArgs)
Protected Friend Overrides Sub OnPreRender (e As EventArgs)
參數
範例
下列程式代碼範例示範如何覆寫 OnPreRender 方法,使其一律會在自定義 TextBox 伺服器控件中顯示一點框線。
重要
這個範例有一個可接受使用者輸入的文字方塊,這可能會造成安全性威脅。 根據預設,ASP.NET Web 網頁會驗證使用者輸入未包含指令碼或 HTML 項目。 如需詳細資訊,請參閱 Script Exploits Overview (指令碼攻擊概觀)。
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Custom TextBox - OnPreRender - C# Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom TextBox - OnPreRender - C# Example</h3>
<aspSample:CustomTextBoxOnPreRender
id="TextBox1"
runat="server">Hello World!
</aspSample:CustomTextBoxOnPreRender>
</form>
</body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Custom TextBox - OnPreRender - VB.NET Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom TextBox - OnPreRender - VB.NET Example</h3>
<aspSample:CustomTextBoxOnPreRender id="TextBox1"
runat="server">Hello World!</aspSample:CustomTextBoxOnPreRender>
</form>
</body>
</html>
using System.Web;
using System.Security.Permissions;
namespace Samples.AspNet.CS.Controls
{
[AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
public sealed class CustomTextBoxOnPreRender : System.Web.UI.WebControls.TextBox
{
protected override void OnPreRender(System.EventArgs e)
{
// Run the OnPreRender method on the base class.
base.OnPreRender(e);
// Display the TextBox with a 1 point border.
this.BorderWidth = System.Web.UI.WebControls.Unit.Point(1);
}
}
}
Imports System.Web
Imports System.Security.Permissions
Namespace Samples.AspNet.VB.Controls
<AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class CustomTextBoxOnPreRender
Inherits System.Web.UI.WebControls.TextBox
Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
' Run the OnPreRender method on the base class.
MyBase.OnPreRender(e)
' Display the TextBox with a 1 point border.
Me.BorderWidth = System.Web.UI.WebControls.Unit.Point(1)
End Sub
End Class
End Namespace