Link to home
Start Free TrialLog in
Avatar of shorriga
shorriga

asked on

CustomValidator Embedding inside DataList SelectedItemTemplate

My goal is to call the call the CustomAcctNumValidate procedure I wrote from a CustomValidator located inside a the SelectedItemTemplate of my DataList. The Textbox that is being validated is also in the SelectedItemTemplate of my DataList.
 
Code (I know this can be done with RangeValidator, but its a test for something else):
 
HTML:
<asp:CustomValidator id="cvAccountNum" runat="server" ErrorMessage="Account Number Must Be Less Than 25 Characters" OnServerValidate="CustomAcctNumValidate" ControlToValidate="txtAcctNum_SelItem"></asp:CustomValidator>
 
VB.NET Code Behind:
Sub CustomAcctNumValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles cvAccountNum.ServerValidate
If args.Value.Length > 25 Then

args.IsValid = False

Else

args.IsValid = True

End If

End Sub

The error is on the cvAccountNum object in the Handles clause:  "Handles clause requres a WithEvents variable"

Declaring a WithEvents variable breaks the CustomValidator.

Any Suggestions?
ASKER CERTIFIED SOLUTION
Avatar of mmarinov
mmarinov

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial