CheckBoxList.OnPreRender(EventArgs) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
クライアントでレンダリングする前に、 CheckBoxList コントロールを構成します。
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)
パラメーター
例
次のコード例では、CheckBoxListのTableStyle クラスの新しいインスタンスを常に返すように、カスタム サーバー コントロールのCreateControlStyle メソッドをオーバーライドする方法を示します。
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<%@ Page language="c#" %>
<!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 CheckBoxList - OnPreRender - C# Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom CheckBoxList - OnPreRender - C# Example</h3>
<aspSample:CustomCheckBoxListOnPreRender
id="CheckBoxList1" runat="server">
<asp:ListItem Selected="True">Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
<asp:ListItem>Item 5</asp:ListItem>
<asp:ListItem>Item 6</asp:ListItem>
</aspSample:CustomCheckBoxListOnPreRender>
</form>
</body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %>
<%@ Page language="VB" %>
<!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 CheckBoxList - OnPreRender - VB.NET Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom CheckBoxList - OnPreRender - VB.NET Example</h3>
<aspSample:CustomCheckBoxListOnPreRender id="CheckBoxList" runat="server"
RepeatLayout="Table" RepeatColumns="2" CellSpacing="3" CellPadding="3">
<asp:ListItem Selected="True">Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
<asp:ListItem>Item 5</asp:ListItem>
<asp:ListItem>Item 6</asp:ListItem>
</aspSample:CustomCheckBoxListOnPreRender>
</form>
</body>
</html>
using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Security.Permissions;
namespace Samples.AspNet.CS.Controls
{
[AspNetHostingPermission(SecurityAction.Demand,
Level = AspNetHostingPermissionLevel.Minimal)]
public class CustomCheckBoxListOnPreRender : CheckBoxList
{
protected override void OnPreRender(EventArgs e)
{
// Run the OnPreRender method on the base class.
base.OnPreRender(e);
// Display the Calendar with a 3 point border.
this.BorderWidth = Unit.Point(3);
}
}
}
Imports System.Web
IMports System.Web.UI.WebControls
Imports System.Security.Permissions
Namespace Samples.AspNet.VB.Controls
<AspNetHostingPermission(SecurityAction.Demand, _
Level:=AspNetHostingPermissionLevel.Minimal)> _
Public Class CustomCheckBoxListOnPreRender
Inherits System.Web.UI.WebControls.CheckBoxList
Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
' Run the OnPreRender method on the base class.
MyBase.OnPreRender(e)
' Display the CheckBoxList with a 3 point border.
Me.BorderWidth = Unit.Point(3)
End Sub
End Class
End Namespace
注釈
OnPreRender メソッドは、主に、CheckBoxList クラスから派生するカスタム コントロールのコントロール開発者によって使用されます。 OnPreRender メソッドを使用すると、派生クラスはデリゲートをアタッチせずにPreRender イベントを処理できます。 これは、派生クラスでイベントを処理するために推奨される手法です。
OnPreRenderメソッドは、ビューステートを保存し、CheckBoxListのコンテンツをレンダリングする前に、必要なプリレンダリング手順を実行します。 CheckBoxList コントロールに含まれる個々のリスト 項目は、現在のAutoPostBack、CausesValidation、およびValidationGroupの値を使用してレンダリングするために初期化されます。
注意 (継承者)
派生クラスで OnPreRender(EventArgs) をオーバーライドする場合は、登録されているデリゲートがイベントを受け取るように、基底クラスの OnPreRender(EventArgs) メソッドを必ず呼び出してください。