• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 403
  • Last Modified:

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?
0
shorriga
Asked:
shorriga
1 Solution
 
mmarinovCommented:
Hi shorriga,

I would suggest you to make CustomAcctNumValidate Public and remove the handles, because you have already set it by OnServerValidate declaration
Regards!
B..M
mmarinov
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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