asp.net CustomValidator 触发,但 ServerValidateEventArgs 值始终为空

发布于 2024-11-09 19:37:10 字数 980 浏览 3 评论 0原文

我在实现 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

命比纸薄 2024-11-16 19:37:10

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文