Dynamically generating control validators

  • Thread starter Thread starter -=Chris=-
  • Start date Start date
C

-=Chris=-

I'm developing a custom server control that will be rendering a form based
on some input. I've tried creating custom validators in vb.net like so:

Dim v1 as RequiredValidator = new RequiredValidator()
Dim vs as ValidationSummary = new ValidationSummary()

RequiredValidator.ControlToValidate = "id of form control here"
RequiredValidator.Enabled = True
RequiredValidator.EnableClientScript = True
RequiredValidator.ErrorMessage = "Test message"

ValidationSummary.ShowSummary = False
ValidationSummary.ShowMessageBox = True
ValidationSummary.EnableClientScript = True
ValidationSummary.Enabled = True


Now when I submit the form, I have a piece of code in the button's onclick
event that does:

Response.Write "Page Validity: " & Me.IsValid

When the fields are not filled in properly, me.IsValid returns false as
expected, but the ValidationSummary never displays the messagebox. It's
almost like the validation controls have to be registered with the
validation summary somehow, and that's not happening.

Any ideas? What am I missing?


Thanks in advance,
Chris
 
How about
Page.Controls.Add( vs );

-=Chris=- said:
I'm developing a custom server control that will be rendering a form based
on some input. I've tried creating custom validators in vb.net like so:

Dim v1 as RequiredValidator = new RequiredValidator()
Dim vs as ValidationSummary = new ValidationSummary()

RequiredValidator.ControlToValidate = "id of form control here"
RequiredValidator.Enabled = True
RequiredValidator.EnableClientScript = True
RequiredValidator.ErrorMessage = "Test message"

ValidationSummary.ShowSummary = False
ValidationSummary.ShowMessageBox = True
ValidationSummary.EnableClientScript = True
ValidationSummary.Enabled = True


Now when I submit the form, I have a piece of code in the button's onclick
event that does:

Response.Write "Page Validity: " & Me.IsValid

When the fields are not filled in properly, me.IsValid returns false as
expected, but the ValidationSummary never displays the messagebox. It's
almost like the validation controls have to be registered with the
validation summary somehow, and that's not happening.

Any ideas? What am I missing?


Thanks in advance,
Chris
 
No dice. I even tried adding the summary control through the IDE using
drag/drop to make sure it was registered. Still no message.

I was minding my own business when bill blurted out:
 
Back
Top