I try to create my own capcha (ctrlCapcha :UserControl) and I would like to use validator, which will display capcha error on ValidationSummary control.
At first I tried to create validator by inherit by BaseValidator class, but I can not pin it to my aspx file (<%# Register %> doesn't work)
At second I tried to use CustomValidator, but when I fix ID of my capcha control asp.net give me error "Control 'ctrlCapcha' referenced by the ControlToValidate property of 'cusValCapcha' cannot be validated." (I service event "OnServerValidate")
Could you tell me which way is better? Thank for you all suggestions :)
What are the fields that are inside the UserControl? I assume you want to validate one of these fields. You can add the Customvalidator to the UserControl itself and implement your ServerValidate inside the codebehind of the user control. You don’t have to set the “ControlToValidate” property. In the ServerValidate, you just add whether validation logic you want.
Related
Does anyone have an example of this? I want to create a TextBox inherited control that creates a CustomValidator within it. I don't believe I can create the CustomValidator as a child of the TextBox. I think it needs to be added as a child of the Page itself (I could be wrong).
Any help??
Thanks!
Ok I figured it out. The validator event wasn't being added to the Page.Validators at the right time. I was creating the validator in the CreateChildControls method. This is wrong. It (they) need to be created in the control's Init method so that they are added to the validator stack during the correct time of the page's life cycle. It was simply a move to this Init method and all works fine now.
[SOLVED] Use WebControl (in this case Panel) to render a DOM-Element with the ClientID as id-attribute, that can be validated.
Didn't find any question/answer to this issue.
I got a UserControl with several DropDownLists (one CheckBox in all of those lists must be checked to get a true validation).
Serverside validation works fine. Clientside validation not.
The OnClickEvent on any of the CheckBoxes doesn't trigger the Javascript code. Also the Sendbutton-Click doesn't trigger the validation for this UserControl.
Is there a way to tell the UserControl to trigger the validation javascript, if any of the Checkboxes in the UserControl gets clicked ?
(btw.: If u use a CustomValidator on CheckBoxLists, it automatically calls the javascript on click on its CheckBoxes, so I think the only Problem is, that i use a Custom UserControl that gets validated by a CustomValidator, so the CustomValidator doesn't get it, that the UserControl has Elements with OnClick-Events)
Solution: Use WebControl (in this case Panel) to render a DOM-Element with the ClientID as id-attribute, that can be validated.
How do I check whether the controls in a usercontrol contain any value?
I have created a usercontrol called ctlCustomerAddress and I want to create an address record in the database if only I have the values in the textboxes.
There are number of ways to validate user input. You may use Validation Control (RequiredField), or write JavaScript code or write server side code to validate the user input.
You can use validation controls. Also write the save to DB code to a button inside the user control rather then the parent page ?
Is a RequiredValidator control what you're looking for? MSDN Reference.
You can also use CustomerValidator and RegularExpressionValidator controls.
Set their ValidationGroup properties to be the same as your submit button.
I seem to have a bit of a bug, I have a ASP.NET repeater control with a link buttons in it and the link button has the have the causes validation property set to false.
However; when clicking it which makes a panel visible on the web page, the asp.net required field validator controls trigger and shows their error messages. On those controls that I have the validator controls on.
Any ideas as to what might cause it to be ignoring the causes validation property set to false?
On my opinion, you should set different ValidationGroup properties values for repeater control and for control that is the source for required field validator. It is possible that container for repeat control has raised event that can be heared by required field validator.
If mentioned above cannot help then try to disable client validation for RequiredFieldValidator using EnableClientScript="False" for it. And activate RequiredFieldValidator when it really usefull. For example in the some button event handler you can apply such code:
MyButton.Validate();
if (MyButton.IsValid)
{
Do what you want...
}
For anybody that has this problem and stumbles across this post, here's what I found.
Turns out the problem was happening because I had EnableViewState="false" set on the Repeater. This was breaking the event postback somehow, and making every validator on the page fire. All I had to do was manually call DataBind() on the Repeater from within Page_Load(), and it cleared right up.
try to set the visablity of the panel true all the time in design view,, and check the validation again.
can we use the same validator of a control for two different buttons,
or do we need to write add a validator for each control for two different buttons.
Each ASP.NET validator control can be bound to exactly one ControlToValidate, except for the CompareValidator. The CompareValidator also has a ControlToCompare property. You need to add a validator for each control you wish to validate.
When you find that your markup gets bloated with validators, you can also create a handy extension methods on Control and let it automaticaly add a new validator to the page. You can invoke this method in your code behind in OnPreInit or OnInit.