我用很少的asp.net控件编写简单的WebPart。 我有验证控件和SharePoint日期时间控件的问题。 标记:
<SharePoint:DateTimeControl ID="dtc" runat="server" DateOnly="true" HoursMode24="true" OnDateChanged="dtc_DateChanged"/>
<asp:CompareValidator ID="valDtc" runat="server" ForeColor="Red" ControlToValidate="dtc$dtcDate"
Type="Date" Operator="DataTypeCheck" ErrorMessage="choose or write correct date (YYYY-MM-DD)">
</asp:CompareValidator>
如果我写了错误的日期,我会收到错误消息,如果我写了正确的日期消息就消失了。但是,在我从日历中选择其他(正确)日期之后,错误消息不会消失(但应该)。 我该如何解决这个问题?
编辑:
尝试使用SharePoint:InputFormCompareValidator:
<SharePoint:InputFormCompareValidator ID="ifval" runat="server" ForeColor="Red" ControlToValidate="dtc"
Type="Date" Operator="DataTypeCheck" EnableClientScript="true" ErrorMessage="choose or write correct date (YYYY-MM-DD)">
</SharePoint:InputFormCompareValidator>
给我错误:
[HttpException (0x80004005): Control 'dtc' referenced by the ControlToValidate property of 'ifval' cannot be validated.]
System.Web.UI.WebControls.BaseValidator.CheckControlValidationProperty(String name, String propertyName) +11200546
System.Web.UI.WebControls.BaseValidator.ControlPropertiesValid() +50
System.Web.UI.WebControls.CompareValidator.ControlPropertiesValid() +72
System.Web.UI.WebControls.BaseValidator.get_PropertiesValid() +44
System.Web.UI.WebControls.BaseValidator.OnPreRender(EventArgs e) +38
Microsoft.SharePoint.WebControls.InputFormCompareValidator.OnPreRender(EventArgs e) +131
System.Web.UI.Control.PreRenderRecursiveInternal() +108
如果我将ControlToValidate =“dtc”更改为“dtc $ dtcDate”,它的行为与CompareValidator相同,选择合适的日期后错误消息不会消失。