当使用“en-GB”时,MaskedEditValidator 会导致 Page.IsValid 为 false。文化
<asp:TextBox id="txtDate" runat="server" Width="70" Text='<%# DataBinder.Eval(Container.DataItem, "Date") %>'/>
<atk:MaskedEditExtender ID="meeDate" CultureName="en-GB" runat="server" Mask="99/99/9999" MaskType="Date" TargetControlID="txtDate" PromptCharacter="_" />
<atk:MaskedEditValidator ID="mevDate" runat="server" ControlExtender="meeDate" ControlToValidate="txtDate" EmptyValueMessage=" *" InvalidValueMessage="Date is invalid" IsValidEmpty="False" CssClass="validatorError" />
以下设置似乎在客户端工作正常(验证器根据 dd/MM/yyyy 进行完美验证),但是当我回发并检查 Page.IsValid 时,该值是 false。我查看了 mevDate.IsValid ,它是错误的。似乎在 MaskedEditExtender 上设置 CultulreName 足以让 MaskedEditValidator 发出正确的 JavaScript,但在服务器端它不起作用。当我将 CultureName 翻转为“en-US”时,客户端和服务器上的一切都按预期工作。
更新
我注意到的一件有趣的事情是在调试过程中,如果您查看 MaskedEditValidator 成员,您会注意到 private 成员 _Culture 设置为“en-US”,而MaskedEditExtender 已正确设置为“en-GB”。似乎没有办法改变这一点。
更新2
我最终得到了下面发布的解决方案。
<asp:TextBox id="txtDate" runat="server" Width="70" Text='<%# DataBinder.Eval(Container.DataItem, "Date") %>'/>
<atk:MaskedEditExtender ID="meeDate" CultureName="en-GB" runat="server" Mask="99/99/9999" MaskType="Date" TargetControlID="txtDate" PromptCharacter="_" />
<atk:MaskedEditValidator ID="mevDate" runat="server" ControlExtender="meeDate" ControlToValidate="txtDate" EmptyValueMessage=" *" InvalidValueMessage="Date is invalid" IsValidEmpty="False" CssClass="validatorError" />
The following setup seems to work fine on the client side (the validator validates perfectly against dd/MM/yyyy), however when I post back and check Page.IsValid, the value is false. I looked at mevDate.IsValid and it's false. It seems that setting the CultulreName on the MaskedEditExtender is sufficient to get the MaskedEditValidator to emit the correct JavaScript, but on the server side of things it doesn't work. When I flip CultureName to "en-US" everything works as expected, both on client and server.
UPDATE
One interesting thing I noticed is during debugging if you look at the MaskedEditValidator members, you’ll notice that the private member _Culture is set to “en-US” while the MaskedEditExtender is properly set to “en-GB”. There doesn't seem to be a way to change this.
UPDATE 2
I ended up with the solution I posted below.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来像一个错误,这可能是您想要在 ASP.NET 论坛上发布的内容...那里有一个 AJAX 控制工具包的论坛,MS 人员也听。
Seems like a bug, that might be something you want to post on the ASP.NET forums... there is a forum for the AJAX control toolkit there that the MS people listen too.
这是我最终得到的解决方法:
Here is the workaround I ended up with: