当使用“en-GB”时,MaskedEditValidator 会导致 Page.IsValid 为 false。文化

发布于 2024-10-16 00:38:06 字数 1039 浏览 3 评论 0原文

<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 技术交流群。

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

发布评论

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

评论(2

薆情海 2024-10-23 00:38:06

看起来像一个错误,这可能是您想要在 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.

饮惑 2024-10-23 00:38:06

这是我最终得到的解决方法:

bool valid = true;
/* Only check Page.IsValid for USCulture, for other cultures MaskedEditValidator only properly works on the client-side 
 * (shows IsValid == false) on the server even though the date is in correct format and passed client side validation. */
if (USCulture)
{
    valid = Page.IsValid;
}
else
{
    /* Even though we are not checking Page.IsValid for non-us cultures, the server will trigger the validation anyway and on the 
     * postback the error message will display.  Here we simply set the .Text property to a HTML comment, for the browser to render nothing
     * as if there is no error.  Setting this property to empty/null causes the control to revert to the original message specified in .aspx. */
    mevCalendar.Text = "<!>";
}

if (valid)
{
    BindGridDataSource(pageNumber);
}

Here is the workaround I ended up with:

bool valid = true;
/* Only check Page.IsValid for USCulture, for other cultures MaskedEditValidator only properly works on the client-side 
 * (shows IsValid == false) on the server even though the date is in correct format and passed client side validation. */
if (USCulture)
{
    valid = Page.IsValid;
}
else
{
    /* Even though we are not checking Page.IsValid for non-us cultures, the server will trigger the validation anyway and on the 
     * postback the error message will display.  Here we simply set the .Text property to a HTML comment, for the browser to render nothing
     * as if there is no error.  Setting this property to empty/null causes the control to revert to the original message specified in .aspx. */
    mevCalendar.Text = "<!>";
}

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