Solved

asp.net validation controls letting bad data through

Posted on 2016-09-22
2
28 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

19 Experts available now in Live!

Get 1:1 Help Now