ValidationSummary.OnPreRender メソッド
このメソッドは,.NET Framework インフラストラクチャをサポートします。独自に作成したコードから直接使用するためのものではありません。
PreRender イベントを発生させます。
名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文
'宣言
Protected Friend Overrides Sub OnPreRender ( _
e As EventArgs _
)
'使用
Dim e As EventArgs
Me.OnPreRender(e)
protected internal override void OnPreRender (
EventArgs e
)
protected public:
virtual void OnPreRender (
EventArgs^ e
) override
protected void OnPreRender (
EventArgs e
)
protected internal override function OnPreRender (
e : EventArgs
)
適用できません。
パラメータ
- e
イベント データを格納している EventArgs。
使用例
OnPreRender メソッドをオーバーライドし、カスタム ValidationSummary サーバー コントロールでエラー メッセージを常に太字で表示する方法を次のコード例に示します。
セキュリティに関するメモ : |
---|
この例には、ユーザー入力を受け付けるテキスト ボックスがあります。これにより、セキュリティが脆弱になる可能性があります。既定では、ASP.NET Web ページによって、ユーザー入力にスクリプトまたは 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 ValidationSummary - AddAttributesToRender - VB.NET Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom ValidationSummary - AddAttributesToRender - VB.NET Example</h3>
<table id="Table1" cellpadding="4" cellspacing="0">
<tr>
<td>
<table id="Table2" cellpadding="4" cellspacing="0" style="background-color:#eeeeee">
<tr>
<td colspan="3"><b>Credit Card Information</b> </td>
</tr>
<tr>
<td align="right">Card Type: </td>
<td><asp:RadioButtonList id="RadioButtonList1" runat="server" RepeatLayout="Flow">
<asp:ListItem>MasterCard</asp:ListItem>
<asp:ListItem>Visa</asp:ListItem>
</asp:RadioButtonList>
</td>
<td align="center" rowspan="1">
<asp:RequiredFieldValidator id="RequiredFieldValidator1"
runat="server" ErrorMessage="Card Type. " Width="100%"
Display="Static" ControlToValidate="RadioButtonList1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">Card Number: </td>
<td><asp:TextBox id="TextBox1" runat="server"></asp:TextBox></td>
<td>
<asp:RequiredFieldValidator id="RequiredFieldValidator2"
runat="server" ErrorMessage="Card Number. " Width="100%"
Display="Static" ControlToValidate="TextBox1">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td></td>
<td><asp:Button id="Button1" runat="server" text="Validate"></asp:Button></td>
<td></td>
</tr>
</table>
</td>
<td valign="top">
<table id="Table3" cellpadding="4" cellspacing="0" >
<tr>
<td><aspSample:CustomValidationSummaryAddAttributesToRender
id="ValidationSummary1" runat="server" DisplayMode="BulletList"
HeaderText="You must enter a value in the following fields:" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
...
Imports System.Web
Imports System.Security.Permissions
Namespace Samples.AspNet.VB.Controls
<AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class CustomValidationSummaryAddAttributesToRender
Inherits System.Web.UI.WebControls.ValidationSummary
Protected Overrides Sub AddAttributesToRender(ByVal writer As System.Web.UI.HtmlTextWriter)
' Show the error message as bold.
writer.AddStyleAttribute(System.Web.UI.HtmlTextWriterStyle.FontWeight, "bold")
' Call the Base's AddAttributesToRender method.
MyBase.AddAttributesToRender(writer)
End Sub
End Class
End Namespace
<%@ 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 ValidationSummary - AddAttributesToRender - C# Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom ValidationSummary - AddAttributesToRender - C# Example</h3>
<table id="Table1" cellpadding="4" cellspacing="0">
<tr>
<td>
<table id="Table2" cellpadding="4" cellspacing="0"
style="background-color:#eeeeee;">
<tr>
<td colspan="3"><b>Credit Card Information</b> </td>
</tr>
<tr>
<td align="right">Card Type: </td>
<td>
<asp:RadioButtonList id="RadioButtonList1" runat="server" RepeatLayout="Flow">
<asp:ListItem>MasterCard</asp:ListItem>
<asp:ListItem>Visa</asp:ListItem>
</asp:RadioButtonList>
</td>
<td align="center" rowspan="1">
<asp:RequiredFieldValidator
id="RequiredFieldValidator1"
runat="server"
ErrorMessage="Card Type"
Width="100%"
Display="Static"
ControlToValidate="RadioButtonList1">*
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">Card Number: </td>
<td><asp:TextBox id="TextBox1" runat="server"></asp:TextBox></td>
<td>
<asp:RequiredFieldValidator
id="RequiredFieldValidator2"
runat="server"
ErrorMessage="Card Number"
Width="100%"
Display="Static"
ControlToValidate="TextBox1">*
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td></td>
<td><asp:Button id="Button1" runat="server" text="Validate"></asp:Button></td>
<td></td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top">
<aspSample:CustomValidationSummaryAddAttributesToRender
id="ValidationSummary1"
runat="server"
DisplayMode="BulletList"
HeaderText="You must enter a value in the following fields:" />
</td>
</tr>
</table>
</form>
</body>
</html>
...
using System.Web;
using System.Security.Permissions;
namespace Samples.AspNet.CS.Controls
{
[AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
public sealed class CustomValidationSummaryAddAttributesToRender : System.Web.UI.WebControls.ValidationSummary
{
protected override void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
{
// Show the error message as bold.
writer.AddStyleAttribute(System.Web.UI.HtmlTextWriterStyle.FontWeight, "bold");
// Call the Base's AddAttributesToRender method.
base.AddAttributesToRender(writer);
}
}
}
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.JSL.Controls" Assembly="Samples.AspNet.JSL" %>
<%@ Page Language="VJ#" 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 ValidationSummary - AddAttributesToRender - VJ# Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom ValidationSummary - AddAttributesToRender - VJ# Example</h3>
<table id="Table1" cellpadding="4" cellspacing="0">
<tr>
<td>
<table id="Table2" cellpadding="4" cellspacing="0"
style="background-color:#eeeeee">
<tr>
<td colspan="3"><b>Credit Card Information</b> </td>
</tr>
<tr>
<td align="right">Card Type: </td>
<td>
<asp:RadioButtonList id="RadioButtonList1" runat="server" RepeatLayout="Flow">
<asp:ListItem>MasterCard</asp:ListItem>
<asp:ListItem>Visa</asp:ListItem>
</asp:RadioButtonList>
</td>
<td align="center" rowspan="1">
<asp:RequiredFieldValidator
id="RequiredFieldValidator1"
runat="server"
ErrorMessage="Card Type"
Width="100%"
Display="Static"
ControlToValidate="RadioButtonList1">*
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">Card Number: </td>
<td><asp:TextBox id="TextBox1" runat="server"></asp:TextBox></td>
<td>
<asp:RequiredFieldValidator
id="RequiredFieldValidator2"
runat="server"
ErrorMessage="Card Number"
Width="100%"
Display="Static"
ControlToValidate="TextBox1">*
</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td></td>
<td><asp:Button id="Button1" runat="server" text="Validate"></asp:Button></td>
<td></td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top">
<aspSample:CustomValidationSummaryAddAttributesToRender
id="ValidationSummary1"
runat="server"
DisplayMode="BulletList"
HeaderText="You must enter a value in the following fields:" />
</td>
</tr>
</table>
</form>
</body>
</html>
...
package Samples.AspNet.JSL.Controls;
public class CustomValidationSummaryAddAttributesToRender
extends System.Web.UI.WebControls.ValidationSummary
{
protected void AddAttributesToRender(System.Web.UI.HtmlTextWriter writer)
{
// Show the error message as bold.
writer.AddStyleAttribute(System.Web.UI.HtmlTextWriterStyle.FontWeight,
"bold");
// Call the Base's AddAttributesToRender method.
super.AddAttributesToRender(writer);
} //AddAttributesToRender
} //CustomValidationSummaryAddAttributesToRender
プラットフォーム
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
Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。
バージョン情報
.NET Framework
サポート対象 : 3.0,2.0,1.1,1.0
参照
関連項目
ValidationSummary クラス
ValidationSummary メンバ
System.Web.UI.WebControls 名前空間