Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
320 views
in Technique[技术] by (71.8m points)

customvalidator - ASP.NET Custom Validator Error Message: Control referenced by the property cannot be validated

I use ASP.NET and have a Button and a CustomValidator, which has to validate the button.

<asp:Button ID="saveButton" runat="server" OnClick="SaveButton_Click" Text="Speichern"
    CausesValidation="true"/>
<asp:CustomValidator runat="server" ID="saveCValidator" Display="Static"
    OnServerValidate="EditPriceCValidator_ServerValidate"   
    ControlToValidate="saveButton" ErrorMessage="">

When loading the page, I receive the error message:

"Control 'saveButton' referenced by the ControlToValidate property of 'saveCValidator' cannot be validated."

What might be the problem? I searched on the net, but this didn′t help much.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

AFAIK, ControlToValidate property should point to input control or left blank for the CustomValidator control.

A reference from MSDN:

Use the ControlToValidate property to specify the input control to validate. This property must be set to the ID of an input control for all validation controls except the CustomValidator control, which can be left blank. If you do not specify a valid input control, an exception will be thrown when the page is rendered. The ID must refer to a control within the same container as the validation control. It must be in the same page or user control, or it must be in the same template of a templated control.

The standard controls that can be validated are:

  • System.Web.UI.WebControls.DropDownList
  • System.Web.UI.WebControls.FileUpload
  • System.Web.UI.WebControls.ListBox
  • System.Web.UI.WebControls.RadioButtonList
  • System.Web.UI.WebControls.TextBox
  • System.Web.UI.HtmlControls.HtmlInputFile
  • System.Web.UI.HtmlControls.HtmlInputPassword
  • System.Web.UI.HtmlControls.HtmlInputText
  • System.Web.UI.HtmlControls.HtmlSelect
  • System.Web.UI.HtmlControls.HtmlTextArea

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...