Wrox Programmer Forums
|
BOOK: Beginning ASP.NET Databases Also see the forum ASP Databases for more general discussions of ASP database issues not directly related to these books.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET Databases 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 December 4th, 2005, 06:34 PM
Authorized User
 
Join Date: Jun 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 7 Validation Example

I'm currently going through this book a second time and re-building several of the TYOs using VS.NET, and splitting out the vb script into code behind files, just so I can get into the habit of doing it that way regularly. (As an aside, the VS.NET environment is so rich that I can't imagine anyone building ASP.NET apps any other way.)

But I have to say that the validation TYO on pp254-255 is really lame. It doesn't trap non-numeric errors! It simply states (in Step 3, at the top of page 3), that "any attempt to update a price with a value that's **not sensible** will result in a friendly error message".

Afraid not! Entering a letter or other nonnumeic character in a field intended for numeric input is a very common user mistake! In this example, a nonnumeric input generates a very ugly server error page.

I tried tweaking the vb script as follows but it didn't work:

Dim pricetextbox As TextBox = CType(e.Item.Cells(2).Controls(0), TextBox)
Dim pricevalue As VariantType = pricetextbox.Text

        'validation code
        'if the value is not numeric, raise the error message
        If (Not (IsNumeric(pricevalue))) Then
            loadgrid()
            With lblError
                .Text = "Please enter a positive numeric value for Product Price."
                .ForeColor = Drawing.Color.Red
                .Visible = True
            End With
            ' if the value IS numeric,
        ElseIf IsNumeric(pricevalue) Then
            'convert it to a decimal;
            Dim myprice As Decimal = Convert.ToDecimal(pricevalue)
            'if it's a negative value or zero, raise the error
            If myprice <= 0 Then
                loadgrid()
                With lblError
                    .Text = "Please enter a positive numeric value for Product Price."
                    .ForeColor = Drawing.Color.Red
                    .Visible = True
                End With
            'if the value IS a positive decimal, perform the update
            ElseIf myprice > 0 Then
                'this will re-render the grid without any input controls
                dgProducts.EditItemIndex = -1
                lblError.Visible = False
                'this function is defined below
                UpdateProduct(ProductID, myprice)
            End If
        End If

Validation and error handling are so important that there should be a totally separate Chapter "7A" devoted to these topics. Not only that, but the don't even tie this example back to the discussion of asp validation controls in Chapter 6. In general, these topics are given really short shrift in this book.

Looks like I'll have to move on to the Pro ASP.NET book to get what I really want in terms of examples.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 2 Package validation error LesThompson BOOK: Expert SQL Server 2005 Integration Services ISBN: 978-0-470-13411-5 0 October 24th, 2008 01:19 PM
Standalone validation + web form validation morbo Struts 0 August 19th, 2008 04:02 AM
Validation using Validation Framework kalyangvd Struts 1 January 2nd, 2008 06:53 AM
Chapter 15 - EMail Validation studentinpain BOOK: Beginning ASP 3.0 1 March 19th, 2004 07:33 AM





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