<asp:button id="cmdCancel" runat="server" Text="Cancel" CausesValidation="False"></asp:button> |
cmdcancel.causesvalidation=false; |
名称 | 描述 |
Page_IsValid | 检验页面中的所有输入是否都合法,返回布尔值 |
Page_Validators | 当前页面中所有验证控件所形成的一个数组 |
Page_ValidationActive | 为一个布尔值,表明是否执行验证功能,设置为false则关闭验证功能。 |
Isvalid | 该属性验证客户端的输入是否合法 |
ValidatorEnable(val, enable) | 该方法将某个验证控件作为传递参数,启动或禁止该控件使用验证功能,在客户端起作用 |
<script language="javascript"> ValidatorEnable(验证控件名称, false) </script> |
<script language="javascript"> for(i=0;i< Page_Validators.length;i++) { ValidatorEnable(Page_Validators[i], false) } </script> |
<script language="javascript"> function enableRegionValidators() { for(i=0;i< Page_Validators.length;i++) { ValidatorEnable(Page_Validators[i], false) } ValidatorEnable(rvRegion, true) } </script> |
cmdRegion.Attributes.Add("onclick","enableRegionValidators();"); |
private void cmdRegion_Click(object sender, System.EventArgs e) { rvStartDate.IsValid=true; rvEndDate.IsValid=true; lblReport.Text = "Region Wise Report For " + txtRegionName.Text.ToUpper(); } |
<form id="Form1" method="post" runat="server"> <TABLE id="Table1" cellSpacing="0" cellPadding="0" width="504" align="center" borderColorLight="#996633" border="1"> <TR> <TD style="FONT-WEIGHT: bold" align="center" colSpan="3">Region Wise Reports</TD> </TR> <TR> <TD>Region Name</TD> <TD> <asp:TextBox id="txtRegionName" runat="server"></asp:TextBox></TD> <TD> <asp:RequiredFieldValidator id="rvRegion" runat="server" ControlToValidate="txtRegionName" ErrorMessage="Region is required"></asp:RequiredFieldValidator></TD> </TR> <TR> <TD></TD> <TD></TD> <TD> <asp:Button id="cmdRegion" runat="server" Text="Get Report"></asp:Button></TD> </TR> </TABLE> <br> <br> <TABLE id="Table2" cellSpacing="0" cellPadding="0" width="504" border="1" align="center" borderColorLight="#996633"> <TR> <TD style="FONT-WEIGHT: bold" align="center" colSpan="3">Date Wise Reports</TD> </TR> <TR> <TD>Start Date</TD> <TD> <asp:TextBox id="txtStartDate" runat="server"></asp:TextBox></TD> <TD> <asp:RequiredFieldValidator id="rvStartDate" runat="server" ControlToValidate="txtStartDate" ErrorMessage="Start Date is required"></asp:RequiredFieldValidator></TD> </TR> <TR> <TD>End Date</TD> <TD> <asp:TextBox id="txtEndDate" runat="server"></asp:TextBox></TD> <TD> <asp:RequiredFieldValidator id="rvEndDate" runat="server" ControlToValidate="txtEndDate" ErrorMessage="End Date is required"></asp:RequiredFieldValidator></TD> </TR> <TR> <TD style="WIDTH: 139px"></TD> <TD></TD> <TD> <asp:Button id="CmdDate" runat="server" Text="Get Report"></asp:Button></TD> </TR> </TABLE> </form> <script language="javascript"> function disableScript() { for(i=0;i< Page_Validators.length;i++) { //Page_Validators[i].isvalid=true; ValidatorEnable(Page_Validators[i], false) } } function enableRegionValidators() { for(i=0;i< Page_Validators.length;i++) { ValidatorEnable(Page_Validators[i], false) } ValidatorEnable(rvRegion, true) } function enableDateValidators() { for(i=0;i< Page_Validators.length;i++) { ValidatorEnable(Page_Validators[i], false) } ValidatorEnable(rvStartDate, true) ValidatorEnable(rvEndDate, true) } </script> <asp:Label id="lblReport" style="Z-INDEX: 101; LEFT: 144px; POSITION: absolute; TOP: 344px" runat="server" Width="344px" Height="24px"></asp:Label> DisableClientValidation.aspx:.cs主要代码: private void Page_Load(object sender, System.EventArgs e) { cmdRegion.Attributes.Add("onclick","enableRegionValidators();"); CmdDate.Attributes.Add("onclick","enableDateValidators();"); } private void cmdRegion_Click(object sender, System.EventArgs e) { rvStartDate.IsValid=true; rvEndDate.IsValid=true; lblReport.Text = "Region Wise Report For " + txtRegionName.Text.ToUpper(); } private void CmdDate_Click(object sender, System.EventArgs e) { rvRegion.IsValid=true; lblReport.Text = "Date Wise Report Betwee " + txtStartDate.Text.ToUpper() + " And " + txtEndDate.Text.ToUpper(); } } |