Solved

asp.net validation controls letting bad data through

Posted on 2016-09-22
2
26 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
Comment Utility
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
Comment Utility
It's easy when you know how!  Thanks.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

10 Experts available now in Live!

Get 1:1 Help Now