Add Validation Control At Run Time

  • Thread starter Thread starter Karl
  • Start date Start date
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
 
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
 
Back
Top