[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1581
  • Last Modified:

Programmatically adding a custom validator?

How do I programmatically add a custom validator? I thought something like this would do:

            Dim validationControl As CustomValidator
            validationControl = New CustomValidator()
            validationControl.ID = "valAllDOBValidator"
            validationControl.ControlToValidate = "dropDOBDD"
            validationControl.Text = "Error Message"
            validationControl.CssClass = "highlight"
            validationControl.Display = ValidatorDisplay.Dynamic
            validationControl.EnableClientScript = "False"
            validationControl.ServerValidate = New ServerValidateEventHandler(AddressOf ALLDOBSValidator_ServerValidate)
            plhOtherInsured.Controls.Add(validationControl)

However I'm getting the following error:

Error      29      'Public Event ServerValidate(source As Object, args As System.Web.UI.WebControls.ServerValidateEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.
0
g-spot
Asked:
g-spot
1 Solution
 
crisco96Commented:
Since this is a local variable you have to use AddHandler:

AddHandler validatoinControl.ServerValidate, AddressOf ALLDOBSValidator_ServerValidate

If it were a global varaible you could also use handles:

Protected Sub ALLDOBSValidator_ServerValidate(sender as object, args as ServerValidateEventArgs) handles validationControl.ServerValidate

...

End Sub

More info:
http://www.thescarms.com/dotnet/EventHandler.asp
0
 
g-spotAuthor Commented:
Brilliant. Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now