Wrox Programmer Forums
|
BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9
This is the forum to discuss the Wrox book Professional ASP.NET 3.5: In C# and VB by Bill Evjen, Scott Hanselman, Devin Rader; ISBN: 9780470187579
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 18th, 2009, 12:48 PM
Authorized User
 
Join Date: Mar 2009
Posts: 74
Thanks: 5
Thanked 0 Times in 0 Posts
Default I need Help Please just read

I am a rookie programmer,
I am trying to create a requiredfield validator using the custom control available in .Net. I know about the inbuilt validators, but the case is that I need to create custom server side validators, therefore I dont want to mix the inbuilt client side validation controls that come with dotnet and the custom server side validators that I need to build. This is why I need to create a custom serverside textbox required field validator. But all efforts failed.THis is what I tried.

protected void e_serverValidate(................................. ... args)
{
if(TextBox1.Text.Trim()=="")
args.IsValid=false;
else
args.isValid=true;
}
Please how am I suppose to write the appriopriate code . Csharp, thank you
 
Old July 2nd, 2010, 01:42 PM
Authorized User
 
Join Date: Aug 2009
Posts: 17
Thanks: 0
Thanked 1 Time in 1 Post
Default

You're making work for yourself.

The built-in validator controls run both client-side and server-side. Since they emit JavaScript to run client-side, and it's really easy to simply disable JavaScript in any modern browser, the developers at Microsoft had the foresight to protect against how easily validation could be by-passed by having the controls operate server-side as well. I believe (and you can double-check this if you'd like), all you have to do is check the Page.IsValid property to find out if any of the validation controls failed validation on Postback (this happens server-side). You can then access the Page.Validators collection to find out which validator failed (there may be an easier way to do this -- Google it).

If you don't want to use the standard validators, then I wouldn't bother creating a control when a simple method / property will do the trick. I'd probably add a property to your page such as the following:

Code:
    public partial class _Default : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.IsValidCustom)
            {
                // DO STUFF HERE
            }

        }

        private readonly bool IsValidCustom
        {
            get
            {
                return string.IsNullOrEmpty(TextBox1.Text.Trim());
            }
        }
    }
If you need to check more controls, then simply add the checks to the IsValidCustom property. If you need custom error messages (perhaps written to a label control), then you need to write your own validation subroutine / function (depends on whether you want some kind of return value or not).

Last edited by Pegasus40218; July 2nd, 2010 at 02:02 PM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
I need Help Please just read ysfkay ASP.NET 3.5 Professionals 1 March 18th, 2009 02:05 PM
Read Only Form Is not Read only lryckman Access VBA 3 June 12th, 2007 06:30 AM
Read First!! I need you o help :-) Stephen Lam MySQL 1 April 15th, 2005 10:12 AM
What to Read Next ralphtrent BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 1 July 17th, 2004 01:53 AM
Read first!!!Please help me!!!Thank you!!! wood000 Wrox Book Feedback 1 June 24th, 2004 09:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.