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

时间:2011-02-07 14:48:27

标签: c# asp.net asp.net-ajax ajaxcontroltoolkit

<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成员,你会注意到私有成员_Culture被设置为“en-US”而MaskedEditExtender被正确设置为“EN-GB”。似乎没有办法改变这一点。

更新2

我最终得到了我在下面发布的解决方案。

2 个答案:

答案 0 :(得分:0)

看起来像一个bug,可能是你想在ASP.NET论坛上发布的东西......那里有一个AJAX控制工具包的论坛,MS人也会听。

答案 1 :(得分:0)

以下是我最终的解决方法:

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);
}