CompareValidator.ControlPropertiesValid メソッド
このメソッドは,.NET Framework インフラストラクチャをサポートします。独自に作成したコードから直接使用するためのものではありません。
コントロールのプロパティに有効な値が設定されているか検証します。
名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文
'宣言
Protected Overrides Function ControlPropertiesValid As Boolean
'使用
Dim returnValue As Boolean
returnValue = Me.ControlPropertiesValid
protected override bool ControlPropertiesValid ()
protected:
virtual bool ControlPropertiesValid () override
protected boolean ControlPropertiesValid ()
protected override function ControlPropertiesValid () : boolean
適用できません。
戻り値
コントロールのプロパティが有効な場合は true。それ以外の場合は false。
例外
例外の種類 | 条件 |
---|---|
ControlToValidate と ControlToCompare の ID が同じです。 |
|
HttpException |
対象となるプロパティの値を適切な Type に変換できません。 |
使用例
次のコード例では、カスタム サーバー コントロールの ControlPropertiesValid メソッドをオーバーライドして、CompareValidator コントロールの ControlToCompare プロパティがページに存在し、検証プロパティを含む限り、常に表示プロパティの値を返す方法を示します。
セキュリティに関するメモ : |
---|
この例には、ユーザー入力を受け付けるテキスト ボックスがあります。これにより、セキュリティが脆弱になる可能性があります。既定では、ASP.NET Web ページによって、ユーザー入力にスクリプトまたは 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 CompareValidator - ControlPropertiesValid - VB.NET Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom CompareValidator - ControlPropertiesValid - C# Example</h3>
<asp:TextBox id="TextBox1" runat="server">123</asp:TextBox><br />
<aspSample:CustomCompareValidatorControlPropertiesValid
id="CompareValidator1" runat="server" Display="Dynamic"
ErrorMessage="The value of TextBox1 must be '456'."
ControlToValidate="TextBox1" ValueToCompare="456" /><br />
<asp:Button id="Button1" runat="server" Text="Button" />
</form>
</body>
</html>
...
Imports System.Web
Imports System.Security.Permissions
Namespace Samples.AspNet.VB.Controls
<AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class CustomCompareValidatorControlPropertiesValid
Inherits System.Web.UI.WebControls.CompareValidator
Protected Overrides Function ControlPropertiesValid() As Boolean
' Determine whether the ControlToValidate is on the page and contains a validation properties.
MyBase.CheckControlValidationProperty(Me.ControlToValidate, "ControlToValidate")
' If the control is visible, then control is valid and ready for validation.
Dim control As System.Web.UI.Control = Me.FindControl(Me.ControlToValidate)
If control.Visible = True Then
Return True
Else
Return False
End If
End Function
End Class
End Namespace
<%@ 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 CompareValidator - ControlPropertiesValid - C# Example</title>
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
// Run the Page Validate method in order to force
// the CompareValidate to show it's error message.
Page.Validate();
}
</script>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom CompareValidator - ControlPropertiesValid - C# Example</h3>
<asp:TextBox id="TextBox1" runat="server">123</asp:TextBox><br />
<aspSample:CustomCompareValidatorControlPropertiesValid
id="CompareValidator1"
runat="server"
Display="Dynamic"
ErrorMessage="The value of TextBox1 must be '456'."
ControlToValidate="TextBox1"
ValueToCompare="456" /><br />
<asp:Button id="Button1" runat="server" Text="Button" />
</form>
</body>
</html>
...
using System.Web;
using System.Security.Permissions;
namespace Samples.AspNet.CS.Controls
{
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class CustomCompareValidatorControlPropertiesValid : System.Web.UI.WebControls.CompareValidator
{
protected override bool ControlPropertiesValid()
{
// Determine whether the ControlToValidate is on the page and contains a validation properties.
base.CheckControlValidationProperty(this.ControlToValidate, "ControlToValidate");
// If the control is visible, then control is valid and is ready for validation.
System.Web.UI.Control control = this.FindControl(this.ControlToValidate);
return control.Visible;
}
}
}
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.JSL.Controls" Assembly="Samples.AspNet.JSL" %>
<%@ Page language="VJ#" %>
<!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 CompareValidator - ControlPropertiesValid - VJ# Example</title>
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
// Run the Page Validate method in order to force
// the CompareValidate to show it's error message.
get_Page().Validate();
} //Page_Load
</script>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom CompareValidator - ControlPropertiesValid - VJ# Example</h3>
<asp:TextBox id="TextBox1" runat="server" Text="123"></asp:TextBox><br />
<aspSample:CustomCompareValidatorControlPropertiesValid
id="CompareValidator1"
runat="server"
Display="Dynamic"
ErrorMessage="The value of TextBox1 must be '456'."
ControlToValidate="TextBox1"
ValueToCompare="456" /><br />
<asp:Button id="Button1" runat="server" Text="Button" />
</form>
</body>
</html>
...
package Samples.AspNet.JSL.Controls;
public class CustomCompareValidatorControlPropertiesValid
extends System.Web.UI.WebControls.CompareValidator
{
protected boolean ControlPropertiesValid()
{
// Determine whether the ControlToValidate is on the page
// and contains a validation properties.
super.CheckControlValidationProperty(this.get_ControlToValidate(),
"ControlToValidate");
// If the control is visible, then control is valid and is ready
// for validation.
System.Web.UI.Control control =
this.FindControl(this.get_ControlToValidate());
return control.get_Visible();
} //ControlPropertiesValid
} //CustomCompareValidatorControlPropertiesValid
プラットフォーム
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
参照
関連項目
CompareValidator クラス
CompareValidator メンバ
System.Web.UI.WebControls 名前空間