2012-03-13 42 views
1

我在我的頁面中有以下控件,我的CompareValidator工作,但不是MaskedEditValidator。我錯過了什麼?爲什麼我的MaskedEditValidator不工作?

<form id="form1" runat="server"> 
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> 
    </asp:ToolkitScriptManager> 
    <div> 
     Date: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
     <asp:CalendarExtender ID="TextBox1_CalendarExtender" runat="server" 
      Enabled="True" TargetControlID="TextBox1"> 
     </asp:CalendarExtender> 
     <asp:MaskedEditExtender ID="TextBox1_MaskedEditExtender" runat="server" 
      CultureAMPMPlaceholder="" CultureCurrencySymbolPlaceholder="" 
      CultureDateFormat="" CultureDatePlaceholder="" CultureDecimalPlaceholder="" 
      CultureThousandsPlaceholder="" CultureTimePlaceholder="" Enabled="True" 
      TargetControlID="TextBox1" Mask="99/99/9999" MaskType="Date"> 
     </asp:MaskedEditExtender> 
     <%--<asp:MaskedEditValidator ID="MaskedEditValidator1" runat="server" 
      ControlExtender="TextBox1_MaskedEditExtender" ControlToValidate="TextBox1" 
      ErrorMessage="The Date is not valid!" IsValidEmpty="False"> 
     </asp:MaskedEditValidator>--%>   
     <asp:CompareValidator ID="CompareValidator1" runat="server" 
      ErrorMessage="Invalid Date!" ControlToValidate="TextBox1" 
      Operator="DataTypeCheck" Type="Date"> 
     </asp:CompareValidator> 
     <br /> 
     <br /> 
     <asp:Button ID="Button1" runat="server" Text="PostBack" 
      onclick="Button1_Click" style="height: 26px; width: 85px" /> 
     <br /><br /> 
     Selected Date:<asp:Label ID="Label1" runat="server"></asp:Label> 
     </div> 
    </form> 
+0

我複製了上面的頁面,MaskedEditExtender工作正常。你的意思是MaskedEditValidator? – jmaglio 2012-03-13 18:10:32

+0

Yeh。我的意思是MaskedEditValidator。如果取消註釋並註釋CompareValidator,並輸入無效日期,則不會顯示錯誤消息「日期無效」。 – GLP 2012-03-13 19:31:47

回答

3

用以下替換您MaskedEditValidator:

<asp:MaskedEditValidator ID="MaskedEditValidator1" runat="server" 
ControlExtender="TextBox1_MaskedEditExtender" ControlToValidate="TextBox1" 
IsValidEmpty="False" EmptyValueMessage="Invalid Date" 
InvalidValueMessage="The Date is not valid!"> 
</asp:MaskedEditValidator> 

關鍵的一點是,你需要InvalidValueMessage和/或EmptyValueMessage代替ERRORTEXT。