|
-
May 20th, 2004, 11:31 AM
#1
Thread Starter
Hyperactive Member
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.
-
May 20th, 2004, 01:14 PM
#2
Frenzied Member
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
-
May 20th, 2004, 01:31 PM
#3
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|