?
Solved

asp.net validation controls letting bad data through

Posted on 2016-09-22
2
Medium Priority
?
44 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 21

Accepted Solution

by:
Randy Poole earned 2000 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

801 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