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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
AFAIK, ControlToValidate property should point to input control or left blank for the CustomValidator control.
A reference from MSDN:
Use the
ControlToValidateproperty to
specify the input control to validate.
This property must be set to the ID of
an input control for all validation
controls except theCustomValidator
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
Method 2
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0