listview validation help on client side not work - asp.net

inside the list view i put a email validation and validation summary, when i press edit it will not validation on client side. how to make it able to validate on client side
<span class="title1">Email Address<span style="margin-left:28px;">:</span></span><span style=" margin-left:100px;">
<asp:TextBox ID="SecurityAnsLabel" runat="server" Text='<%# Bind("EmailAdd") %>' Height="25px" Width="200px"/>
<asp:RegularExpressionValidator ID="regexEmailValid" runat="server" ValidationExpression="\w+([-+.]\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*" ControlToValidate="SecurityAnsLabel" ErrorMessage="Invalid Email Format" ForeColor="Red" Text="*" SetFocusOnError="True"></asp:RegularExpressionValidator></span>

Set the ValidationGroup property of all the controls(textbox, regular expression control,the button if there is any) involved in this as same like 'EmailValidate'
Hope this works :)

Related

Required Field Validator are not working

I used asp required field in my code but data in text box are sending even they are empty when clicking on the button and after they are sending, message of required field appears!!
Please help! Thanks in advance...
The source code looks like this
<asp:Label ID="LabelUserName" runat="server" AssociatedControlID="UserName" meta:resourcekey="UserName">Nom :</asp:Label>
<asp:TextBox ID="UserName" runat="server" ValidationGroup="val" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Entrez your name " ControlToValidate="UserName" ForeColor="Red" ValidationGroup="val">
</asp:RequiredFieldValidator>
Here is the code of the button :
<asp:Button runat="server" Text="Envoyer" ID="Button1" Width="78px" ValidationGroup="val" />
Can't say for sure without seeing the code inside the event handle for your button click, but my guess is you are missing a check to be sure the page is valid. For example:
If (Page.IsValid) Then
' do your thing
Else
'do nothing
End If
I think the required will help you to solve this issue of field validator
eg:
<asp:TextBox ID="UserName" runat="server" required="required"></asp:TextBox>

Can I have RequiredFieldValidator to check for more than one ControlToValidate?

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" />

ASP.NET:Required Field Validator not working

I've got a weird problem that i don't understand why it happened.
I made a content page so a user can send me a message to my email and made a few TextBox's that are linked to some validators.
when i first made the page i hed 1 Regular Expression validator and every thing worked out fine like i planed it, But then i decided to delete the Regular Expression validator and now i got a problem with the Required Field validator.
when i press submit the page do a post back like there isn't any validators on the page.
I'm pretty sure I'm missing something (I'm pretty new at asp.net)
here is the markup:
<!-- Regular Expression Validtor for the Name Text Box
<asp:RegularExpressionValidator ID="NameExpressionValidator1" runat="server" ControlToValidate="nameTextBox"
ValidationExpression="[אבגדהוזחטיכלמנסעפצקרשתץףןם\s\.]*" Display="Dynamic"> </asp:RegularExpressionValidator> -->
<!--The Name Text Box -->
<asp:TextBox ID="nameTextBox" class="TextBoxes" runat="server"
AutoPostBack="True" ValidationGroup="g" ></asp:TextBox> <span class="infoText">:שם</span>
<!-- Required Field Validator for the Name Text Box -->
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="nameTextBox"
Display="Dynamic" ValidationGroup="g" ErrorMessage="please enter your name"></asp:RequiredFieldValidator>
<br />
<br />
<!-- Phone Text Box -->
<asp:TextBox ID="phoneTestBox" class="TextBoxes" runat="server"
AutoPostBack="True" ValidationGroup="g" ></asp:TextBox> <span class="infoText">:טלפון</span>
<!-- Requierd Field Validator Phone Text Box -->
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="phoneTestBox"
Display="Dynamic" ValidationGroup="g" ErrorMessage="please enter your phone"></asp:RequiredFieldValidator>
<br />
<br />
<asp:TextBox ID="messagTextBox" runat="server" class="TextBoxes" TextMode="MultiLine"
Text="asdasdadasdasdasd"></asp:TextBox> <span class="infoText">:הודעה</span>
<asp:Button ID="button" runat="server" Text="send message" ValidationGroup="g" />
You should not use HTML comments to comment out server side controls but <%-- --%>:
<%--
<asp:RegularExpressionValidator ID="NameExpressionValidator1" runat="server" ControlToValidate="nameTextBox"
ValidationExpression="[אבגדהוזחטיכלמנסעפצקרשתץףןם\s\.]*" Display="Dynamic"> </asp:RegularExpressionValidator>
--%>
http://msdn.microsoft.com/en-us/library/4acf8afk.aspx
Is there any specific use of AutoPostBack="True" in textbox? if not then just remove it from all textboxes, also you need to give ValidationGroup="g" for only validator controls, there is no need to give it in textbox controls.
first of all, ensure the validation group of the validation summary matches?
If that's correct try using validation method:
protected void Page_Load(object sender, EventArgs e)
{
Validate();
}

Validation Summary does not render correctly

Has anyone ever seen this and does anyone know how to fix it ...
The validation Summary control seems to be rendering this :
error message
<br>
error message
<div style="display: none;" id="summaryID">
</div>
Correct me if i'm wrong here but shouldn't my errors be inside that div ... hense the reason you can put a cssclass on the control server side using CssClass="whatever" ?
Or did i miss something?
EDIT :
Just to verify ... this is what i expect it to render :
<div style="display: none;" id="summaryID">
error message
<br>
error message
</div>
EDIT 2 :
Server side markup that produces this is ...
<asp:ValidationSummary ID="ui_ValidationSummary" runat="server" />
...
Loads of controls but here's an example (don'twant to over complicate things) :
...
<asp:TextBox ID="ui_txtClientDOB" runat="server" />
<asp:RangeValidator ID="ui_RangeValidator_DOB" runat="server" ControlToValidate="ui_txtClientDOB" ErrorMessage="DOB is not valid" MinimumValue="1900/01/01" Type="Date" ForeColor="Red">*</asp:RangeValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="ui_txtClientDOB" ErrorMessage="DOB is missing" ForeColor="Red">*</asp:RequiredFieldValidator>
If either validator on this textbox has reason to fail the validation the result is as discussed, an empty div tag with an error next to it.
Likely the div #summaryID is where client side validation errors are show. Use a tool like firebug to see this as you can't do a view source on javascript filled markup. Otherwise, turn off client side validation and do a postback.
Edit
My guess is that you are mixing up the error message that's displayed with the validation control itself instead of inside the validation summary. If you don't supply a text property to the validation controls it will use the error message. Try the following (take away the text property and you'll see what I mean):
<asp:ValidationSummary ID="val" runat="server" CssClass="test"
DisplayMode="List" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1" ErrorMessage="RequiredFieldValidator" Text="*"></asp:RequiredFieldValidator>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="TextBox2" ErrorMessage="RequiredFieldValidator" Text="*"></asp:RequiredFieldValidator>
<asp:Button ID="Button1" runat="server" Text="Button" />

ASP.NET Validation styling

I'm using ASP.NET WebForms and using some validation like the following:
<asp:TextBox runat="server" ID="txtUserName" CssClass="Email" /><br />
<asp:RequiredFieldValidator runat="server" ID="rfvUserName" Display="Dynamic" ControlToValidate="txtUserName" ErrorMessage="Please enter your email address" CssClass="Error" />
<asp:RegularExpressionValidator Enabled="false" runat="server" ID="revUserName" Display="Dynamic" ControlToValidate="txtUserName" ErrorMessage="Please enter a valid email address" ValidationExpression="<%$ Resources:Global, RegExEmail %>" />
What I want to do is instead of just showing a message below in the form of a span I would like to alter the textbox itself, such as add a red border around it and change its background to have an error icon. How do I do this? Thanks.
what about ValidatorCallout? It looks nice and let you add custom CSS class to validated field when it's content is invalid.Also it's a part of popular Ajax Toolkit by Microsoft.

Resources