In my asp.net application, I've tried to use validation summary in my web page.I've controls like
<td>First Name *</td>
<td>
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
<div>
<asp:RequiredFieldValidator ID="reqValStaffFirstName" runat="server"
ErrorMessage="Enter FirstName" Text="*"
ControlToValidate="txtFirstName" Display="Dynamic"
ValidationGroup="valGrpStaffGeneral">
</asp:RequiredFieldValidator>
</div>
</td>
<td>Last Name *</td>
<td>
<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox>
<div>
<asp:RequiredFieldValidator ID="reqValStaffLastName" runat="server"
ErrorMessage="Enter LastName" Text="*"
ControlToValidate="txtLastName" Display="Dynamic"
ValidationGroup="valGrpStaffGeneral">
</asp:RequiredFieldValidator>
</div>
</td>
<td>
<asp:Button Id="btnSave" runat="server" ValidationGroup="valGrpStaffGeneral">
<td>
and my validationsummary script is
<asp:ValidationSummary ID="summary1" ShowSummary="true" runat="server"
ValidationGroup="valGrpStaffGeneral" DisplayMode="BulletList" />
If I click on save button without filling anything in textbox1 and textbox2 its showing validation errors in my validation summary area. If I fill anything in my textboxes and press tab the error(*) disappears automatically, but the error in the validation summary not changing automatically and its displaying until I click on save button, what should I do to make the validation summary change the fixed errors automatically.
This might be of help - look at the EnableClientScript property of the ValidationSummary control.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.validationsummary.enableclientscript.aspx
Related
I have required field validation control for a radiobutton list. So if no values are selected then it gives me a error which is fine. But when i redo select something and click the button then it does't not fires the server event of the button. Once i have the validation erro then whatever i do it disable the server side event.
any ideas why is it happening my code
<div id="studysub_popul" runat="server" visible="false">
<asp:Label ID="lbl_rdb_study_popul" runat="server"
CssClass="questions"
Text="2.Select your study subjects">
</asp:Label>
<asp:RadioButtonList ID="rdb_study_popul" runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="rdb_study_popul_SelectedIndexChanged">
<asp:ListItem>Individuals</asp:ListItem>
<asp:ListItem>Population</asp:ListItem>
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
ControlToValidate="rdb_study_popul"
Display="Dynamic"
ErrorMessage="Study Subject is required"
ValidationGroup="StudySubject">
</asp:RequiredFieldValidator>
</div>
</td>
</tr>
<tr>
<td>
<asp:Button ID="btn_s_section" runat="server"
OnClick="btn_studysubject_section_Click"
Text="Next" ValidationGroup="StudySubject"
Visible="false" />
</td>
You should add a validating group to the RadioButtonList definition too.
<asp:RadioButtonList ID="rdb_study_popul" runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="rdb_study_popul_SelectedIndexChanged"
ValidationGroup="StudySubject">
In the code below, the submit buttion has the 'SubmitValidation' ValidationGroup.
When i change the name of the ValidationGroup in the RequiredFieldValidator (to submitValidation123), the Error Message 'Enter State Code' does not appear (as expected). However, the submit does not take place till I actually enter a value for the state code. WHY?
<tr>
<td>
<span class="requiredText">*</span> State Code (Ex. TX):
</td>
<td>
<asp:TextBox runat="server" ID="statecodeTxt" Width="100px"></asp:TextBox>
<asp:RequiredFieldValidator ID="statecodeRFV" runat="server"
Display="Dynamic" ValidationGroup="submitValidation"
ControlToValidate="statecodeTxt" SetFocusOnError="True"
ErrorMessage="Enter State Code" />
</td>
</tr>
<asp:Button ID="submitBtn" Text="Submit" disabled="true"
runat="server" ValidationGroup="submitValidation"
OnClick="submitBtn_Click" />
Try remove or make false the
SetFocusOnError="True"
I am having 3 TextBoxes in a row and then a Next button.
On clicking Next button, the control would go to the next page only if ALL of the 3 TextBoxes contain some user-entered text.
Is there any option by which I can check whether all of the TextBoxes contain some text by using RequiredFieldValidator (rather than going for different RequiredFieldValidator for each ControlToValidate)?
I am currently having following code:
<tr>
<td class="style1">
<asp:Label ID="lblDOB" runat="server" Font-Bold="True" Font-Italic="False" Font-Size="Medium"
ForeColor="Black" Text="Date of Birth"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtA" runat="server" Width="45px"></asp:TextBox>
<asp:TextBox ID="txtB" runat="server" Width="45px"></asp:TextBox>
<asp:TextBox ID="txtC" runat="server" Width="45px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server"
ControlToValidate="txtA"
ErrorMessage="Please enter Text">
</asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server"
ControlToValidate="txtB"
ErrorMessage="Please enter Text">
</asp:RequiredFieldValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server"
ControlToValidate="txtC"
ErrorMessage="Please enter Text">
</asp:RequiredFieldValidator>
</td>
</tr>
So, instead of having 3 different RequiredFieldValidators, I want to use only a single RequiredFieldValidator which checks if all the 3 TextBoxes contain some text. How can I achieve this?
Your best bet is to use CustomValidator and combine with either client side javascript or server side c#/vb.net code.
You can't validate more than one control using RequiredFieldValidator.
you can't use the RequiredFieldValidator with more than one control ,
but i prefer to use the HTML5 required attribute instead of ASP.NET Validation.
<asp:TextBox ID="txt1" required="required" />
Hi I have a change password page.
I have 2 textboxes, New Password and Confirm Password.
Both have a requiredFieldValidators.
And a compareValidator.
But what happens is when I key in the first field New Password, the second textbox's requiredFieldValidator and CompareValidator are showing error messages at the same time.
I only want to show requiredFieldValidator and only when that validator returns true, I want to validate compareValidator.
How can I achieve that. The following is my code.
<table class="editAccTable">
<tr>
<td>
New Password<br />
<asp:TextBox ID="txtNewPwd" runat="server" TextMode="Password" Width="204px"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="rfvNewPwd" runat="server"
ControlToValidate="txtNewPwd"
ValidationGroup="vgChangePwd"
Display="Dynamic"
></asp:RequiredFieldValidator>
</td>
<td>
Confirm New Password<br />
<asp:TextBox ID="txtConfPwd" runat="server" TextMode="Password" Width="204px"></asp:TextBox>
<br />
<asp:RequiredFieldValidator ID="rfvConfPwd" runat="server"
ControlToValidate="txtConfPwd"
ValidationGroup="vgChangePwd"
Display="Dynamic"
></asp:RequiredFieldValidator>
<asp:CompareValidator ID="cvChangePwd" runat="server"
ValidationGroup="vgChangePwd"
ControlToValidate="txtNewPwd"
ControlToCompare="txtConfPwd"
ValueToCompare="String"
Display="Dynamic"
></asp:CompareValidator>
</td>
</tr>
<tr>
<td colspan="2">
<asp:ImageButton ID="ibtnPwdChange" runat="server"
ImageUrl="/images/submit.jpg" onclick="ibtnPwdChange_Click"
ValidationGroup="vgChangePwd"
Width="90px" Height="36px"
/>
<br />
<asp:Label ID="lblSuccessPwdChange" runat="server"></asp:Label>
</td>
</tr>
</table>
There is a couple of work around.
For my case, I can remove the requiredFieldValidator for the second textbox as it is enough to have only compareValidator.
But there will be some cases, that there must have 2 validators. In that case, we can use css to overlap the 2 validators.
Try CompareValidator like this
<asp:CompareValidator id="cvChangePwd" runat="server" ControlToValidate="txtConfPwd" ControlToCompare="txtNewPwd" ErrorMessage="Your passwords do not match up!" Display="Dynamic" />
set display property as dynamic
display="dynamic" in all the validators
I have a basic ASP.NET website which has a register page with the user name, password and email as text boxes. Only one of them, the email, has a validation which is the default email validation from ASP.NET.
After the validation, I want the cursor to be in the email textbox if the validation fails.
Currently the message is displayed but the cursor is not on the page.
<tr>
<td>
<asp:TextBox ID="txtPassword" runat="server" CssClass="cpTextBox" TextMode="Password"
TabIndex="7" ToolTip="Password must be at least six characters in length"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvPassword" runat="server" ControlToValidate="txtPassword"
ErrorMessage="Please enter password" Display="None">*</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revPassword" runat="server" ControlToValidate="txtPassword"
ErrorMessage="Password must be at least six characters in length" ValidationExpression=".{6,50}"
Display="None">*</asp:RegularExpressionValidator>
</td>
<td>
<asp:TextBox ID="txtTitle" runat="server" CssClass="cpTextBox" TabIndex="11"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblVerifyPassword" runat="server" CssClass="cpLabel" Text="Verify password"></asp:Label>
<asp:Label ID="Label4" runat="server" ForeColor="Red" Text="*"></asp:Label>
</td>
<td>
<asp:Label ID="lblPhone" runat="server" CssClass="cpLabel" Text="Phone"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtVerifyPassword" runat="server" CssClass="cpTextBox" TextMode="Password"
TabIndex="8"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvConfirmPassword" runat="server" ControlToValidate="txtVerifyPassword"
ErrorMessage="Please verify the password" Display="None">*</asp:RequiredFieldValidator>
<asp:CompareValidator ID="cvVerifyPassword" runat="server" ControlToCompare="txtPassword"
ControlToValidate="txtVerifyPassword" ErrorMessage="Please verify the password"
Display="None">*</asp:CompareValidator>
</td>
Can someone guide me on how to do this?
Regards.
For the validator control please set SetFocusOnError="true"