Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic control ? 1

Status
Not open for further replies.

hanglam

Programmer
Dec 11, 2002
143
0
0
US
I created a control and a RequiredField Validator programatically .
My problem is when I tried to set the RequiredFieldValidator.ControlToValidate = Control, it gives me an error .

For example:

dim text as Textbox
dim required as RequiredFieldValidator

text = new Textbox
required = new RequiredFieldValidator
required.ControlToValidate = text (!! Error in this line)

It gives me an error when I tried to assigned the textbox control to the validator .

Any ideas ?

Thanks,
Hang

 
What is the error you are getting?

Have you tried declaring these WithEvents. I am not sure that would make a difference but you might want to try:

Protected WithEvents text as Textbox
Protected WithEvents required as RequiredFieldValidator

required.ControlToValidate = text

Eva
 
The problem is that for the ControlToValidate property of validator, you need to give a string which is the ID of your textbox control.

The code should be as

Dim text As TextBox
Dim required As RequiredFieldValidator

text = New TextBox()
text.ID = "t1"
required = New RequiredFieldValidator()
required.ControlToValidate = "t1"
 
thanks, that sounds about right ...
I used the control.ClientID property ...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top