Results 1 to 3 of 3

Thread: create RangeValidator at Runtime [RESOLVED]

  1. #1

    Thread Starter
    Hyperactive Member johnweidauer's Avatar
    Join Date
    Sep 2002
    Location
    SLC, UT
    Posts
    314

    create RangeValidator at Runtime [RESOLVED]

    I am dynamically creating my form because the information I want in this form is controlled by a database and therefore needs to be dynamic. I am creating a RangeValidator:
    Code:
                    QtyVal = New RangeValidator()
                    QtyVal.ID = CStr("ValQty" & DBReader("ProdSKU"))
                    QtyVal.Attributes.Add("Type","Integer")
                    QtyVal.ControlToValidate = CStr(NewTxtBx.ID)
                    QtyVal.MaximumValue = "30"
                    QtyVal.MinimumValue = "1"
                    QtyVal.Attributes.Add("runat","server")
                    QtyVal.Text = "<BR>Must be between 1 and 30"
                    QtyVal.Attributes.Add("display","static")
    My problem is that it validates the values as a string (i.e. User enter 1-3 everything ok, 4 and up and validation dies). Any ideas?
    Last edited by johnweidauer; May 20th, 2004 at 01:38 PM.

  2. #2
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    1) Make sure the control is actually being added to the page (view the source in the browser)

    2) The RangeValidator already has a type property, so you don't need to add it as an attribute, just set it in the code.
    Code:
    QtyVal.Type = ValidationDataType.Integer
    3) The ControlToValidate property will just be the string name of the control. It will probably be the ClientID property of the textbox, since the control is being validated on the client.
    Code:
    QtyVal.ControlToValidate = NewTxtBx.ClientID.ToString()
    4) You don't need to add the runat="server' attribute. Just make sure you add the control to the page properly.

    5) You don't need to add the "display" attribute to the control, because the RangeValidator has a display property you can just set in code.
    Code:
    QtyVal.Display = ValidatorDisplay.Static
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  3. #3

    Thread Starter
    Hyperactive Member johnweidauer's Avatar
    Join Date
    Sep 2002
    Location
    SLC, UT
    Posts
    314

    Range Problem [RESOLVED]

    Ok, I have changed my code to be as shown below.

    Code:
                QtyVal = New RangeValidator()
                QtyVal.ID = CStr("ValQty" & DBReader("ProdSKU"))
                QtyVal.Type = ValidationDataType.Integer
                QtyVal.ControlToValidate = NewTxtBx.ClientID.ToString()
                QtyVal.MaximumValue = 30
                QtyVal.MinimumValue = 1
                QtyVal.Display = ValidatorDisplay.Static
                QtyVal.Text = "<BR>Must be between 1 and 30"
    Thank you very much for your assistance.
    Last edited by johnweidauer; May 20th, 2004 at 01:38 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width