asp.net CustomValidator 触发,但 ServerValidateEventArgs 值始终为空
我在实现 CustomValidator 时遇到问题,我有多个带有 MaskedEditExtender 的文本框,它们都应包含日期 ("dd-MM-yyyy"
)。要检查此日期,我想使用 CustomValidator,但传递给 MyValidate 函数的 e.Value 始终为空,而 TextBox 则不是。
代码:
<asp:TextBox ID="Gereed" runat="server" CssClass="date" />
<asp:CustomValidator ID="cd1" runat="server" TargetControlID="Gereed" />
<asp:MaskedEditExtender ID="md1" runat="server" TargetControlID="Gereed"
Mask="99-99-9999" ClearMaskOnLostFocus="false"/>
代码隐藏:
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
cd1.ValidateEmptyText = True
AddHandler cd1.ServerValidate, AddressOf ValidateDate
End Sub
Protected Sub ValidateDate(ByVal sender As Object, ByVal e As ServerValidateEventArgs)
e.IsValid = MyValidate(e.Value, "dd-MM-yyyy")
End Sub
我有一个 ClientValidationFunction 也有同样的问题。
有谁知道这个问题的解决方案吗?我想我错过了一些东西,但我不知道是什么,另一个网站中的类似解决方案效果很好。
I'm having a problem implementing a CustomValidator, I have multiple TextBoxes with a MaskedEditExtender, they all should contain a date ("dd-MM-yyyy"
). To check this date I want to use the CustomValidator, but the e.Value passed to my MyValidate function is always empty, while the TextBox is not.
code:
<asp:TextBox ID="Gereed" runat="server" CssClass="date" />
<asp:CustomValidator ID="cd1" runat="server" TargetControlID="Gereed" />
<asp:MaskedEditExtender ID="md1" runat="server" TargetControlID="Gereed"
Mask="99-99-9999" ClearMaskOnLostFocus="false"/>
code behind:
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
cd1.ValidateEmptyText = True
AddHandler cd1.ServerValidate, AddressOf ValidateDate
End Sub
Protected Sub ValidateDate(ByVal sender As Object, ByVal e As ServerValidateEventArgs)
e.IsValid = MyValidate(e.Value, "dd-MM-yyyy")
End Sub
I had a ClientValidationFunction that has the same problem.
Does anyone know a solution to this? I guess I'm missing something, but I don't know what, a similar solution in another website works perfectly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TargetControlID 不是 CustomValidator 的属性,它应该是 ControlToValidate。不知怎的,没有错误消息,如果未找到 ControlToValidate,普通验证器会抛出异常,但 CustomValidator 不会。
TargetControlID is not a property of CustomValidator, it should be ControlToValidate. Somehow there was no errormessage, normal Validators throw an exception if ControlToValidate was not found, but the CustomValidator does not.