CommandField.CausesValidation 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
사용자가 필드에서 단추를 CommandField 클릭할 때 유효성 검사가 수행되는지 여부를 나타내는 값을 가져오거나 설정합니다.
public:
virtual property bool CausesValidation { bool get(); void set(bool value); };
public override bool CausesValidation { get; set; }
member this.CausesValidation : bool with get, set
Public Overrides Property CausesValidation As Boolean
속성 값
true 사용자가 필드에서 단추를 CommandField 클릭할 때 유효성 검사를 수행하려면 이고, false그렇지 않으면 . 기본값은 true입니다.
예제
다음 코드 예제에서는 필드의 CausesValidation 단추를 CommandField 클릭할 때 유효성 검사가 발생 하지 않도록 속성을 사용 하는 방법을 보여 줍니다.
중요합니다
이 예제에는 잠재적인 보안 위협인 사용자 입력을 허용하는 텍스트 상자가 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력에 스크립트 또는 HTML 요소가 포함되지 않는지 확인합니다. 자세한 내용은 스크립트 악용 개요를 참조하세요.
<%@ 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 runat="server">
<title>CommandField CausesValidation Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>CommandField CausesValidation Example</h3>
<!-- Normally, the validation controls declared in the -->
<!-- EditItemTemplate of each TemplateField field column would -->
<!-- prevent the user from leaving a field value empty; however, -->
<!-- because the CausesValidation property of the CommandField -->
<!-- field column is set to false, validation does not occur when -->
<!-- the user clicks a button in the CommandField field column. -->
<asp:gridview id="CustomerGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="false"
datakeynames="CustomerID"
cellpadding="10"
runat="server">
<columns>
<asp:commandfield showeditbutton="true"
causesvalidation="false"
headertext="Edit"/>
<asp:boundfield datafield="CustomerID"
headertext="Customer ID"
readonly="true"/>
<asp:templatefield headertext="Company Name"
itemstyle-verticalalign="Top">
<itemtemplate>
<%#Eval("CompanyName")%>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="CompanyNameTextBox"
text='<%#Bind("CompanyName")%>'
width="90"
runat="server"/>
<br/>
<asp:requiredfieldvalidator id="CompanyNameRequiredValidator"
controltovalidate="CompanyNameTextBox"
display="Dynamic"
text="Please enter the company name."
runat="server"/>
</edititemtemplate>
</asp:templatefield>
<asp:templatefield headertext="Address"
itemstyle-verticalalign="Top">
<itemtemplate>
<%#Eval("Address")%>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="AddressTextBox"
text='<%#Bind("Address")%>'
width="90"
runat="server"/>
<br/>
<asp:requiredfieldvalidator id="AddressRequiredValidator"
controltovalidate="AddressTextBox"
display="Dynamic"
text="Please enter the address."
runat="server"/>
</edititemtemplate>
</asp:templatefield>
<asp:templatefield headertext="City"
itemstyle-verticalalign="Top">
<itemtemplate>
<%#Eval("City")%>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="CityTextBox"
text='<%#Bind("City")%>'
width="90"
runat="server"/>
<br/>
<asp:requiredfieldvalidator id="CityRequiredValidator"
controltovalidate="CityTextBox"
display="Dynamic"
text="Please enter the city."
runat="server"/>
</edititemtemplate>
</asp:templatefield>
</columns>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:sqldatasource id="CustomersSqlDataSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City] From [Customers]"
updatecommand="Update [Customers] Set [CompanyName]=@CompanyName, [Address]=@Address, [City]=@City Where [CustomerID] = @CustomerID"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
<%@ 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 runat="server">
<title>CommandField CausesValidation Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>CommandField CausesValidation Example</h3>
<!-- Normally, the validation controls declared in the -->
<!-- EditItemTemplate of each TemplateField field column would -->
<!-- prevent the user from leaving a field value empty; however, -->
<!-- because the CausesValidation property of the CommandField -->
<!-- field column is set to false, validation does not occur when -->
<!-- the user clicks a button in the CommandField field column. -->
<asp:gridview id="CustomerGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="false"
datakeynames="CustomerID"
cellpadding="10"
runat="server">
<columns>
<asp:commandfield showeditbutton="true"
causesvalidation="false"
headertext="Edit"/>
<asp:boundfield datafield="CustomerID"
headertext="Customer ID"
readonly="true"/>
<asp:templatefield headertext="Company Name"
itemstyle-verticalalign="Top">
<itemtemplate>
<%#Eval("CompanyName")%>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="CompanyNameTextBox"
text='<%#Bind("CompanyName")%>'
width="90"
runat="server"/>
<br/>
<asp:requiredfieldvalidator id="CompanyNameRequiredValidator"
controltovalidate="CompanyNameTextBox"
display="Dynamic"
text="Please enter the company name."
runat="server"/>
</edititemtemplate>
</asp:templatefield>
<asp:templatefield headertext="Address"
itemstyle-verticalalign="Top">
<itemtemplate>
<%#Eval("Address")%>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="AddressTextBox"
text='<%#Bind("Address")%>'
width="90"
runat="server"/>
<br/>
<asp:requiredfieldvalidator id="AddressRequiredValidator"
controltovalidate="AddressTextBox"
display="Dynamic"
text="Please enter the address."
runat="server"/>
</edititemtemplate>
</asp:templatefield>
<asp:templatefield headertext="City"
itemstyle-verticalalign="Top">
<itemtemplate>
<%#Eval("City")%>
</itemtemplate>
<edititemtemplate>
<asp:textbox id="CityTextBox"
text='<%#Bind("City")%>'
width="90"
runat="server"/>
<br/>
<asp:requiredfieldvalidator id="CityRequiredValidator"
controltovalidate="CityTextBox"
display="Dynamic"
text="Please enter the city."
runat="server"/>
</edititemtemplate>
</asp:templatefield>
</columns>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:sqldatasource id="CustomersSqlDataSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City] From [Customers]"
updatecommand="Update [Customers] Set [CompanyName]=@CompanyName, [Address]=@Address, [City]=@City Where [CustomerID] = @CustomerID"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
설명
이 속성을 사용하여 필드의 CausesValidation 단추를 CommandField 클릭할 때 유효성 검사가 수행되는지 여부를 지정합니다. 이 속성이 설정 true되면 기본적으로 페이지의 모든 유효성 검사 컨트롤의 유효성이 검사됩니다. 유효성 검사를 특정 유효성 검사 컨트롤 그룹으로만 제한하려면 유효성 검사 그룹을 만든 다음 유효성 검사 그룹의 이름으로 속성을 설정합니다 ValidationGroup . 유효성 검사 그룹에 대한 자세한 내용은 다음을 참조하세요 BaseValidator.ValidationGroup.