I have one asp content page.Its contain many controls like dropdownlist,textbox etc.All controls are inside a div tag.I gave required field validator for all my drop down list.i have one SAVE button that reside inside another div tag.I gave SAVE button cause validation true.But my problem is that, the validator is not working and the page.Isvalid property is true.What is the problem with my code?
Please make sure you have set the ControlToValidate property to the DropDownList id. Also you need to set the InitialValue property on the RequiredFieldValidator when validating a DropDownList. This basically just tells the Validator which item is the intial value (which will throw a validation error when it is selected).
Hope this helps,
Neil
Related
I have a radiobutton list that the items are dynamically filled. Now, I have a required field validator that works as expected (if I do a postback, it will ask me to select an item in the radiobuttonlist).
When I click on Next, I clear the radiobuttonlist, and dynamically fill it again with the next set of data. But now, the required field validator's message is already there asking me to select an item (without doing a postback).
Any ideas to make the required field validator message only become triggered if I do a postback?
Thanx
You should be able to disable the required field validator client side validation with the following:
ValidatorEnable($("#<%=ReqVal.ClientID%>")[0], false);
Replace the ReqVal with the id of your RequiredFieldValidator that you want to disable.
I have a RegularExpressionValidator for a TextBox in a control, which itself is part of another control. When I click the button to submit the form, it seems that it should not do so unless all child controls are properly validated. However, what ends up happening is that I see the validation error message pop up for each control that failed to validate before the page posts back anyway and fails when it can't parse the malformed input.
I have tried surrounding the failing code with if (Page.IsValid) {...} to make sure it doesn't run without complete validation, but the property ends up being true by the time I hit the breakpoint.
Shouldn't an entire page be invalid if any child controls are not successfully validated?
Do you have different ValidationGroup controls defined? As long as the validators in the same validation group as the button are all setup correctly, yes it should block. Unless, for some reason, the JS is failing to load for the validators.
HTH.
Set "CausesValidation = true " to your submit button, I guess your problem will be solved.
Have you called Page.Validate() before using Page.IsValid ?
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 had ddl and I added compare validator to make user choose from DDl.And I set all it,s properties well but when i forget to select ddl the validator apear well but when I selected from ddl The astrics(*) as error text it was still apear although I added it,s property focus on error=true.So please any one help me.
*
You should probably try to use another validator. It sounds like using the CustomValidator instead of the CompareValidator would be your way to go.
The asterix means that one of your validators says that your page is not valid. Try to set a breakpoint and determine which validator is not valid.
I have textboxes which is placed inside accordian (ajax control).In pageload event i have written the code to load values in textboxes. But onload event one error is coming as object not set to instance of a object. Values are not coming in textboxes.
Then i tried to initialize controls in textboxes .Then the error cleared. But
Values are not coming in textboxes. What may be the reason for this?
Have you set the properties of the Accordian properly?
If yes, check the values which you are assigning to the textbox. If they are blank, the values won't be visible.
Try giving a hardcoded value to your textbox and check if it appears or not -
textboxObject.Text = "Hello World!";
At a guess, as the Textbox is a child control of the accordian you possible have to use the AccordianObject.FindControl() method to find your textbox.
More information or posting some code would help, otherwise we are just going to be taking stabs in the dark.