开发者

How can I access textbox properties in a custom validator?

开发者 https://www.devze.com 2022-12-19 15:55 出处:网络
I want to build a custom validator control that inherits from BaseValidator.It will only be used on textboxes in my asp.net application.How can I get acces开发者_开发知识库s to the textbox itself (rea

I want to build a custom validator control that inherits from BaseValidator. It will only be used on textboxes in my asp.net application. How can I get acces开发者_开发知识库s to the textbox itself (read properties of the textbox) within the custom validator?

Here is what I have in my EvaluateIsValid function:

 Dim t As TextBox = CType(Page.FindControl(Me.ControlToValidate), TextBox)
 Return t.Text.Length <= t.MaxLength

It can't seem to find the control, so it breaks with a null reference exception. Can I do this another way?

Thanks!


To get the textbox:

Dim t As TextBox = CType(Me.FindControl(Me.ControlToValidate), TextBox)

0

精彩评论

暂无评论...
验证码 换一张
取 消