Solved

asp.net validation controls letting bad data through

Posted on 2016-09-22
2
31 Views
Last Modified: 2016-09-22
If I type xx into the textbox it violates the regular expression validator.  If I leave it blank, it violates the requiredfield validator.
In either case, I can simply ignore the messages and submit the form.
How can I give these controls the power to stop postback?

I'm using C# web forms with visual studio 2010.


 <asp:Label ID="lblExpectedProcessingDuration" runat="server" Text="ExpectedProcessingDuration" Font-Size="Small"  Width ="15%"></asp:Label>
    <asp:TextBox ID="TxtExpectedProcessingDuration" runat="server" 
        Font-Size="Small"  Width ="25%" MaxLength="4"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate ="TxtExpectedProcessingDuration" ErrorMessage="Please enter expected processing duration" Text ="*" Display="Dynamic" ValidationGroup="Something"></asp:RequiredFieldValidator>
            <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ErrorMessage="Expected processing duration must be numeric" 
            ControlToValidate="TxtExpectedProcessingDuration" Display="Dynamic" ValidationExpression="^[0-9]+$">
            </asp:RegularExpressionValidator>

Open in new window

0
Comment
Question by:AlHal2
2 Comments
 
LVL 21

Accepted Solution

by:
Randy Poole earned 500 total points
ID: 41810978
in your code behind for your save/submit button you would  do something like
 protected void btnSave_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                SaveRecord();
            }
        }

Open in new window

0
 

Author Closing Comment

by:AlHal2
ID: 41811019
It's easy when you know how!  Thanks.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 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