[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.
Related
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.
I have an ASP.NET webpage with several updatepanels. I have a row of buttons (inside an updatepanel) which are connected to another updatepanel by async triggers.
Further down the page, outside any updatepanels, I have a filefield control with a few validators associated. The filefield works well, but when I call one of the buttons inside the updatepanel mentioned previously, it fires the validators associated with the filefield.
Is this supposed to happen? I thought that the asyncronious triggers only made a partial postback with respect to only the contents inside updatepanels.
Kind regards, Casper
go to each button in the update panel, and change its corresponding property CausesValidation to False
I am building a user registration form in asp.net. I want to check if the username is available or not on the leave event of the TextBox. I am not able to get the Leave Event of the TextBox.
Should I use OnBlur event of the Html TextBox.
Please Help.
How about using TextChanged server-side event and wrapping the whole thing in an UpdatePanel for very quick ajax functionality.
If you use this method make sure the AutoPostBack property is set to true for the TextBox control.
I have created a custom control and a custom validator (extending BaseValidator). On custom control I have set ValidationProperty("Values"). The problem is that validation doesn't work when postback is sent unless I execute Page.Validate(). And when I call Page.Validate() all validators are executed which is not what I would expect on postback.
How do I create custom validator which would be executed when control value changes and validates just that control?
That is not how validators work. Unless you are using a ValidationGroup setting, all the validators on your page will automatically fire. You do NOT have to explicitly call Page.Validate(). You DO need to wrap your code in a check like this, however:
if(Page.IsValid)
{
//do something here
}
Unlike client-side validators, the server-side validation does NOT prevent the page from posting back and processing events as normal.
To create a control which only validates when the control value changes would require a bit of hackery, since the change event fires after the validators have been executed.
Have you tried using validation groups?
I have a ASP.NET 2.0 webpage with 2 UserControls (.ascx). Each UserControl contains a bunch of validators. Placing a ValidationSummary on the page will display all validation errors, of both UserControl's. Placing a ValidationSummary in each UserControl will display all the errors of both controls twice.
What I want is a ValidationSummary for each UserControl, displaying only the errors on that UserControl.
I've tried to solve this by setting the ValidationGroup property of the validators on each usercontrol dynamicaly. That way each validationsummary should display only the errors of its UserControl. I've used this code:
foreach (Control ctrl in this.Controls)
{
if (ctrl is BaseValidator)
{
(ctrl as BaseValidator).ValidationGroup = this.ClientID;
}
}
ValidationSummary1.ValidationGroup = this.ClientID;
This however seems to disable both clientside and server side validation, because no validation occurs when submitting the form.
Help?
The control that is causing your form submission (i.e. a Button control) has to be a part of the same validation group as any ValidationSummary and *Validator controls.
If you use ValidationGroups, the validation only occurs if the control causing the postback is assign to the same ValidationGroup.
If you want to use a single control to postback you can still do this but you would need to explicitly call the Page.Validate method.
Page.Validate(MyValidationGroup1);
Page.Validate(MyValidationGroup2);
if(Page.IsValid)
{
//do stuff
}
Suggestion:
Why don't you expose a public property on your user controls called ValidationGroup?
In the setter you could explicitly set the validation group for each validator. You could also use your loop, but it would be more efficient to set each validator explicitly. This might improve the readability of the code using the user controls.