RangeValidator和validationSummary怎么不能共存呢?
放了一个textbox后面跟一个RangeValidation. 下面一个按钮,再跟一个validationSummary.
其中RangeValidation的属性:visible=false, controlToValidata指向textbox.值域设置为1-10
运行,发现不能报错(输入11,ValidationSummary不报错)
但是如果把RangeValidation的 visible=true,则能够报错。
可是我想让RangeValidation不显示,而让ValidationSummary显示错误信息。不知道错在哪里,该怎么办。
附源码:
//Default.aspx
<form id= "form1 " runat= "server ">
<div>
<asp:Label ID= "Label1 " runat= "server " Text= "Please enter 1-10: "> </asp:Label>
<asp:TextBox ID= "txtEnterNumber " runat= "server " CausesValidation= "True "> </asp:TextBox> <asp:RangeValidator
ID= "RangeValidator1 " runat= "server " ErrorMessage= "Out of Range " MaximumValue= "10 "
MinimumValue= "1 " Type= "Integer " ControlToValidate= "txtEnterNumber " Visible= "False " > </asp:RangeValidator>
<br />
<br />
<asp:Button ID= "btSubmit " runat= "server " Text= "submit " OnClick= "btSubmit_Click " />
<asp:Label ID= "lblMessage " runat= "server "> </asp:Label> <br />
<br />
<asp:ValidationSummary ID= "ValidationSummary1 " runat= "server " HeaderText= "Your page contains following errors: " />
</div>
</form>
//Default.aspx.cs
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btSubmit_Click(object sender, EventArgs e)
{
if (!RangeValidator1.IsValid)
{
return; //When RangeValidator test that the the textBox has entered a invali