首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MaskedEditValidator导致使用"en-GB“区域性时Page.IsValid为假。

MaskedEditValidator导致使用"en-GB“区域性时Page.IsValid为假。
EN

Stack Overflow用户
提问于 2011-02-07 14:48:26
回答 2查看 1.2K关注 0票数 2
代码语言:javascript
复制
<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

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-02-11 15:33:07

以下是我最终得到的解决办法:

代码语言:javascript
复制
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);
}
票数 0
EN

Stack Overflow用户

发布于 2011-02-07 16:00:27

似乎是个bug,这可能是你想在ASP.NET论坛上发布的东西……在那里有一个AJAX控制工具包的论坛,MS的人也在听。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4922612

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档