Add Validation Control At Run Time

K

Karl

Can anyone tell me how to add a required field validator
control at run-time?

I have a form that the textbox controls are all added at
run-time. This all works fine.

When I add a validator control and associate it with the
textbox that was just added dynamically I get no errors,
but the validation does not take place on the server or
client side.

Is there some specail step I need to preform to wire up
the client side and sever side events? I have not been
able to find any example code showing the proper method to
perform this.

Thank you very much for the help,

Karl
 
K

Karl

Teemu,

I wrote a demo to send you and it started working. I
think what I was doing wrong, was not supply all the
required properties. When I used the code below, all
works just fine.

Thank you,

Karl

rf = New RequiredFieldValidator
rf.Display = ValidatorDisplay.Dynamic
rf.ErrorMessage = "You must enter a value"
rf.Text = "*"
rf.ControlToValidate = "txt" + intX.ToString
rf.EnableClientScript = True
rf.Enabled = True
rf.EnableViewState = True
rf.ToolTip = rf.ErrorMessage
rf.Visible = True
rf.ID = "rf" + intX.ToString
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top