<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,这是假的。在CultulreName上设置MaskedEditExtender似乎就足以让MaskedEditValidator发出正确的JavaScript,但在服务器端却无法工作。当我将CultureName切换到"en-US“时,所有的东西都可以正常工作,无论是在客户端还是服务器上。
更新
我注意到的一件有趣的事情是,在调试期间,如果您查看MaskedEditValidator成员,您会注意到私有成员_Culture被设置为“en-US”,而MaskedEditExtender则正确地设置为“en-GB”。似乎没有办法改变这种状况。
更新2
最后我得到了我在下面发布的解决方案。
发布于 2011-02-11 15:33:07
以下是我最终得到的解决办法:
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);
}发布于 2011-02-07 16:00:27
似乎是个bug,这可能是你想在ASP.NET论坛上发布的东西……在那里有一个AJAX控制工具包的论坛,MS的人也在听。
https://stackoverflow.com/questions/4922612
复制相似问题