Solved

regularexpressionvalidator  and requiredfieldvalidator

Posted on 2013-01-31
7
229 Views
Last Modified: 2013-02-22
Is there a way to use regularexpressionvalidator  and requiredfieldvalidator on a single textbox?
0
Comment
Question by:VBdotnet2005
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 38840382
You can have more than one validator control to validate a single textbox you simply add both validator controls and set the ControlToValidate attribute on both validator controls to the textbox id.
0
 

Author Comment

by:VBdotnet2005
ID: 38840487
Do I need to use "Display = "Dynamic"?  I want the message to display either message.

*invalid $ amount or *Required field
0
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 38840545
The Display attribute determines whether the validation controls have space allocated on the page for them or they are added to the page when the failure occurs.

Generally you would set Display= Dynamic so that you don't have empty space on the page.
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:VBdotnet2005
ID: 38840584
I tried below. It still postback when txtprice is empty. It does display "*required" though.

<asp:TextBox ID="txtprice" runat="server"></asp:TextBox><asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtprice" ErrorMessage="Incorrect Amount" ValidationExpression="^-?([1-9]\d*|(\d+))(\.\d{2})$" ValidationGroup="Group_price" Display="Dynamic"></asp:RegularExpressionValidator><asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtprice" ErrorMessage="*Required" ValidationGroup="Group_price" Display="Dynamic"></asp:RequiredFieldValidator>
0
 
LVL 20

Expert Comment

by:informaniac
ID: 38840803
Have you set the ValidationGroup property for the submit button?

Also check if there are any other javascript errors on the page using Firebug plugin for Firefox. If there are any javascript errors on the page, then the page will postback.
0
 
LVL 10

Accepted Solution

by:
Monica P earned 500 total points
ID: 38846563
u may get sample here to fix it off

http://forums.asp.net/t/1852836.aspx/1
0
 
LVL 20

Expert Comment

by:informaniac
ID: 38918778
Wow. Looks like I should have shown you an example instead of asking you a question. Very good. It's a lesson for me. Thanks @VBdotnet2005
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now