CompareValidator.ControlPropertiesValid 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
컨트롤의 속성에서 유효한 값을 확인합니다.
protected:
override bool ControlPropertiesValid();
protected override bool ControlPropertiesValid();
override this.ControlPropertiesValid : unit -> bool
Protected Overrides Function ControlPropertiesValid () As Boolean
반환
true컨트롤 속성이 유효한 경우 그렇지 않으면 . false
예외
예제
다음 코드 예제에서는 컨트롤의 속성이 페이지에 있고 유효성 검사 속성을 포함 하는 한 항상 표시 되는 속성 ControlToCompare 의 값을 반환 하도록 사용자 지정 서버 컨트롤에서 메서드를 재정 ControlPropertiesValid 의 CompareValidator 하는 방법을 보여 줍니다.
중요합니다
이 예제에는 잠재적인 보안 위협인 사용자 입력을 허용하는 텍스트 상자가 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력에 스크립트 또는 HTML 요소가 포함되지 않는지 확인합니다. 자세한 내용은 스크립트 악용 개요를 참조하세요.
<%@ 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>
<%@ 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>
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;
}
}
}
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