Required Field validator asp.net - asp.net

I have more than one RequiredFieldvalidator in my markup, I want to check that all fields are entered, and if not I want to show an alert saying so.

Try ValidationSummary control
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
http://asp-net-example.blogspot.nl/2008/10/validationsummary-example-how-to-use.html

Related

How to make regex validator in ASP.NET to stop insertion of data?

I have a grid view in ASP.NET, one of the column of the grid is time(hh:mm). I have used validators for the field. They look like this
<FooterTemplate>
<asp:TextBox ID="st_timef" runat="server"/>
<asp:RegularExpressionValidator ID="stRegularExpressionValidator" runat="server" ErrorMessage="HH:MM!"
ValidationExpression="/(?:[01]?\d|2[0-3]):(?:[0-5]\d)$/" ControlToValidate="st_timef" />
<asp:RequiredFieldValidator ID="stValidator" runat="server" ControlToValidate="st_timef" Text="*" ValidationGroup="validaiton"/>
</FooterTemplate>
The validators work,but I have a problem with the regex validator,
Although it shows a error on wrong input format,but it still allows me to press the button which updates the data,(which is not the case of normal validator).
I need the validator to stop running my update function ones it shows a error in validation.
You must have to set the common validation group name of ValidationGroup property for TextBox, Button and RegularExpression validator.
how to make the error disappear once the correct format is inserted?
Set error description to the Text property of validation control (Set empty string to ErrorMessage property).

ValidationSummary for display validation error messages

i am using validation control of asp.net . i got 10 fields and i have field validators with each of them . Now I want to show error but using ValidationSummary but errors also appear with individual validators. cant i close the individual error messages?
have you add a validation group.
try like this
<asp:ValidationSummary ID="ValidationSummaryVerifyInfo"
ValidationGroup="Verify" runat="server" DisplayMode="List"
ShowMessageBox="True" ShowSummary="False" />
<asp:RequiredFieldValidator ID="RFVEmail" runat="server"
ErrorMessage="Please enter Email Id." ForeColor="Red" SetFocusOnError="True"
ValidationGroup="Verify" ControlToValidate="TextBoxEmail">*</asp:RequiredFieldValidator>
To hide the validators you can place them into one div with CSS style display: none.

Form Validators firing on Umbraco

We are developing a web application in Umbraco 4 and have come across an intermittent problem when posting data between pages. When a form submission is posted to a new page all of the validators are firing causing various unwanted results, we have tried various posting methods using different buttons with the same result. Has anyone else come across this issue?
The validation group is working but I got to the bottom of the issue.
One of the submit buttons on the page was a html submit, with no runat server, so the code-behind didn't know where the submit had come from, so all validations where fired, regardless of validation group
All postbacks events, unless otherwise specified, will cause all validators on a page to be triggered. Either...
A) Set the ValidationGroup property on each of the validators as well as the control which you do want to trigger validators to the same name.
<asp:RequiredFieldValidator ID="valName" runat="server" AssociatedControlID="txtName" ValidationGroup="AllRequired" />
<asp:TextBox ID="txtName" runat="server" />
<asp:Button ID="btnSubmit" runat="server" ValidationGroup="AllRequired" OnClick="..." />
<asp:Button ID="btnSkip" runat="server" OnClick="..." />
In this case, btnSkip won't trigger the validators.
B) Set the CausesValidation property on the control which you don't want to trigger validation to false.
<asp:Button ID="btnSubmit" runat="server" CausesValidation="false" OnClick="..." />

2 user controls on registered on one aspx page not validating validation properly

I have 2 user controls on registered on one aspx page.
UserControl1 us having one text box with require field and one submit button.
UserControl2 is also having one text box with requirefiled and save button.
Expected o/p is-
When I am clicking on any button out of 2(submit or save). Then only related text boxof that user control should be validate.
But the error is
Both text boxes are validate.
Please help me .
Set the ValidationGroup properties to limit which fields get validated when the buttons are pressed.
So for example, if these were contained within the first user control:
<asp:requiredfieldvalidator id="NameValidator"
controltovalidate="NameTextBox"
validationgroup="UserControlOne"
errormessage="required"
runat="Server" />
<asp:button id="Submit"
text="Submit"
causesvalidation="true"
validationgroup="UserControlOne"
runat="Server" />
Clicking the "Submit" button would only cause the validators that have UserControlOne specified as the ValidationGroup to validate.
Edit: When you call Page.Validate() you are validating every group on the page. Call the overloaded Page.Validate(validationGroup) to validate a specific one. e.g. Page.Validate("UserControlOne")

Client Side Validation for different control events

I have a custom validator attached to a textbox control as follows
<td align="center" width="10px">
<asp:CustomValidator ID="validateDateText" ControlToValidate="dateTextBox"
runat="server" OnServerValidate="ValidateDate"
ClientValidationFunction="Validate_Date" EnableClientScript="true"
Width="10px" CssClass="errortext" Text="*" Font-Size="Medium" Font-Bold="true" />
</td>
<td align="center" width="80px">
<asp:Textbox ID="dateTextBox" MaxLength="100" runat="server"
CssClass="dateselectortextbox" style="margin-right: 3px;" />
</td>
When I click a button on the page with causesvalidation="true" the client script fires and the validation summary reflects the error message and the validator shows the *
However when I click out of the textbox only the * is displayed by the validator the validationsummary is not updated
The client side validation is working as the serverside code does not get called im just trying to work out why the validationsummary does not get updated on the onblur event
Any ideas?
EDIT:
The ErrorMessage is set in the codebehind for the validator
I have added the EnableClientScript to my validationsummary
I have added ValidationGroup to my validationsummary, customvalidator, textbox and button, but still the validation summary updates for the button click but not the textbox onblur event
You definitely need to use the errormessage="xyz" for the message to show in the validation summary. The validation group shouldn't matter unless you have more than one group of controls you're validating.
Here is a link to another post that may help you with getting the validation summary to update after the onblur.
I think you might want to use ErrorMessage ="Some informative error message" inside your CustomValidator. You also need set ValidationGroup ="SomeGroupName" for CustomValidator ,ValidationSummary control and also the control which is causing postback.
You need to set dateTextBox.ValidationGroup, validateDateText.ValidationGroup and yourValidationSummary.ValidationGroup to the same value.
See http://msmvps.com/blogs/brianmadsen/pages/ASP.Net-2.0-_2D00_-How-to-use-the-new-validation-features_2C00_-part-1.aspx.

Resources