Trouble with Range Validator

Posted on 2008-11-08
Last Modified: 2012-05-05
I have a range field validator that checks a quantity textbox for a product before its added to a shopping cart to be between 1 and 10. It works the first time but when the user trys to add more of the same product and enters any number other than 1, even if its in the range, it gives the error.
Question by:ashp87
    LVL 8

    Expert Comment

    Can you show some code please? Its better to detect some error.
    LVL 1

    Author Comment

    this is in the page load, the quantity is required before someone can add a item to the cart:
        Protected Sub btnYes_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnYes.Click
            objDT = Session("Cart")
            Dim Product = lbResults.SelectedItem.Text
            Dim blnMatch As Boolean = False

            For Each Me.objDR In objDT.Rows
                If objDR("Product") = lbResults.SelectedItem.Text Then
                    objDR("Quantity") += txtQuantity.Text
                    blnMatch = True
                    Exit For
                End If

            If Not blnMatch Then
                objDR = objDT.NewRow
                objDR("Quantity") = txtQuantity.Text
                objDR("Product") = Product
                objDR("Cost") = Decimal.Parse(20)
            End If
            Session("Cart") = objDT

            dg.DataSource = objDT

            Session("Total") = GetItemTotal()
            lblTotal.Text = "$" & GetItemTotal()
        End Sub
    LVL 1

    Author Comment

    i made a mistake on the post above its not in the page load, i changed teh code i was pasting and i forgot to delete that comment
    LVL 1

    Author Comment

    apparently, it doesnt matter what happens, the first time I click add to cart, the next time i try to add to cart, even if the value is in range, it will come up saying its not in range.
    LVL 20

    Accepted Solution

    Have u set the datatype of the range validator? By default it is string. u will need to change it.
    LVL 1

    Author Comment

    the thing was, in the properties it was set , but when i manually set it in the code, it stopped giving me problems....

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    734 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

    24 Experts available now in Live!

    Get 1:1 Help Now