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

前端 未结 2 2025
长情又很酷
长情又很酷 2020-12-18 20:42

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



        
相关标签:
2条回答
  • 2020-12-18 20:56

    You can only use a CustomValidator against Input controls that accept user input:

    Client-side validation enhances the validation process by checking user input before it is sent to the server.

    What you want to do is look here at Button Controls and Validation.

    0 讨论(0)
  • 2020-12-18 20:59

    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
    0 讨论(0)
提交回复
热议问题