I have a page with TextBox to enter a Mobile Number.
For that I have validated it using RequiredFieldValidator and RegularExpressionValidator
with display=none:
And also I have placed a ValidationSummary Control
<asp:ValidationSummary ValidationGroup="mobile" ShowSummary="false" ID="vsValid"
runat="server" ShowMessageBox="true" Enabled="true"
DisplayMode="SingleParagraph" />
<asp:TextBox ID="txtMobileNumber" runat="server" CssClass="Qinputbox"></asp:TextBox>
<asp:RequiredFieldValidator Display="None" ControlToValidate="txtMobileNumber"
ID="reqValidMobileNo" runat="server" ErrorMessage="*"
ValidationGroup="mobile"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ControlToValidate="txtMobileNumber" Display="None"
ID="regExValidMobileNo" runat="server"
ErrorMessage="Please enter a valid mobile number."
ValidationExpression="^((\+){0,1}91(\s){0,1}(\-){0,1}(\s){0,1}){0,1}9[0-9]
(\s){0,1}(\-){0,1}(\s){0,1}[1-9]{1}[0-9]{7}$"
ValidationGroup="mobile"></asp:RegularExpressionValidator>
when I entered characters in the TextBox it is not showing the summary.
What might be the problem?
From you code fragment:
ShowSummary="false" Looks like a problem.
You should set either ShowSummary="false" to true or EnableClientScript="true". I'm assuming that you want the latter because you have ShowMessageBox="true".
Have a look: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.validationsummary.enableclientscript%28v=vs.71%29.aspx
Use this property to specify whether
the ValidationSummary control updates
itself using client-side script. When
set to true, client-side script is
rendered on the client to update the
ValidationSummary control, if the
browser supports that feature. When
set to false, no client-side script is
rendered on the client and the
ValidationSummary control only updates
itself on round-trips to the server.
In this situation, the ShowMessageBox
property has no effect.
In web.config setting:
<httpRuntime targetFramework="4.5"/>
This setting turns off Javascript injection of validation (client side).
Remove this and retry.
Ensure that you do NOT have this in the web.config file:
<xhtmlConformance mode="Legacy"/>
Related
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
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.
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="..." />
I have big web page, among other there is TextBox and RequiredRangeValidator.
<asp:textbox id="tbNewSvrLic" runat="server" Text="0" BackColor="#FFFFA0" />
<asp:RangeValidator id="NewSvrLicValidator" ControlToValidate="tbNewSvrLic"
runat="server" Type="Integer" MinimumValue="0" MaximumValue="5"
errormessage="Invalid value specified for Additional Server Licenses"
Display="Dynamic" />
<asp:button id="btnOrderSummary" OnClick="btnOrderSummary_Click"
runat="server" text="Display" Visible="False" />
These control are non visible when page is loaded 1st time, but became visible after user do some actions on page and submit some data to server (there Visible status will be changed to true).
When invalid data (for example 10 value) is entered into 'tbNewSvrLic' control then required error message is displayed, but 'Display' button is still clickable and does post-back request to server.
Web site is working under .NET 4.0, very similar functionality is implemented for .NET 3.5, but works as expected...
Please advise. Any thoughts are welcome.
P.S. Probably I need to mention that error message (on validation controls) are displayed in black, not in red as usual...
Can you try using ValidationGroups as mentioned here ?
What is the best way to debug a CompareValidator that always fails the validation? Is there any way to see what the values are that it's comparing to maybe get a clue as to what's going wrong?
Use Firebug to debug the javascript that .Net inserts
If you are not familiar with the other debugging methods, easiest way for you may be utilizing the Response.Write calls to print the values in your button event to see if they are equal to each other:
Response.Write(TextBox1.Text.ToString().Trim());
Response.Write(TextBox2.Text.ToString().Trim());
Response.End();
Update
For simplicity, I will use CompareValidator to check a data type.
You probably have something similar to the following in your ASPX (client side) code:
<asp:TextBox ID="txtTest" runat="server" />
<asp:CompareValidator ID="cvTest" runat="server"
ControlToValidate="txtTest"
Operator="DataTypeCheck" Type="Date"
Display="Dynamic" ErrorMessage="Incorrect format!" />
<asp:Button ID="btnTest" Text="Test Compare Validator"
onclick="btnTest_Click" runat="server" />
In your codebehind (server side), put the following in your btnTest_Click event to see the value that is entered in txtTest:
Response.Write(txtTest.Text.ToString().Trim());
Response.End();
But keep in mind that there more robust debugging utilities that VS offers. This is just a quick-and-dirty way for your purpose.