来自calendarextender的选定日期未填入asp.net文本框中

时间:2014-03-13 06:19:07

标签: asp.net

我有一个文本框和图像按钮。单击图像按钮,calendarextender将出现,calendarextender中的选定日期应该填充在文本框中。但是日期不会填充。请指导我解决此问题。

这是我的代码

<asp:TextBox ID="txtAccidentDate" MaxLength="10" Text=""
     runat="server" SkinID="ClaimTextBox" Width="80px" TabIndex="1" />

<cc1:MaskedEditExtender ID="MaskedEditExtender2" runat="server" 
      TargetControlID="txtAccidentDate" Mask="99/99/9999"
      MessageValidatorTip="false" MaskType="Date"
      DisplayMoney="Left" AcceptNegative="Left"
      ErrorTooltipEnabled="True" />

<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
     runat="server" ControlToValidate="txtAccidentDate" 
     Display="None" 
     ErrorMessage="Please select Accident Date" 
      ValidationGroup="Insured" SetFocusOnError="true">
</asp:RequiredFieldValidator>

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" 
     runat="server" ControlToValidate="txtAccidentDate"
     ValidationGroup="Insured" Display="None"
     ErrorMessage="Please Enter valid Date" 
     SetFocusOnError="true"
     ValidationExpression="(((0?[1-9]|1[012])[/.](0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])[/.](29|30)|(0?[13578]|1[02])/31)[/.](19|[2-9]\d)\d{2}|0?2[/.]29[/.]((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))">
</asp:RegularExpressionValidator>

<cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender5" 
     runat="server" Enabled="True"
     TargetControlID="RegularExpressionValidator2">
</cc1:ValidatorCalloutExtender>

<cc1:ValidatorCalloutExtender ID="ValidatorCalloutExtender6"
     runat="server" Enabled="True" 
     TargetControlID="RequiredFieldValidator1">
</cc1:ValidatorCalloutExtender>

<cc1:CalendarExtender ID="CalendarExtender2" 
     runat="server" Enabled="True"
     PopupButtonID="imgcal" Format="MM/dd/yyyy"
     TargetControlID="txtAccidentDate" />

<asp:ImageButton ID="imgcal" runat="server" CausesValidation="false" 
     ImageUrl="~/Images/Calendar_scheduleHS.png" /> 

<span class="helpInformantion">(mm/dd/yyyy)</span> 

2 个答案:

答案 0 :(得分:0)

我认为你已经使用了ScriptManager。只需使用 ToolScriptManager ,而不是 ScriptManager

即,

更改此

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

 <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>

试试此代码

 <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
        <asp:TextBox ID="txtAccidentDate" MaxLength="10" Text="" runat="server" SkinID="ClaimTextBox" Width="80px" TabIndex="1" />

        <asp:MaskedEditExtender ID="MaskedEditExtender2" runat="server" TargetControlID="txtAccidentDate" 
            Mask="99/99/9999" MessageValidatorTip="false" MaskType="Date" DisplayMoney="Left" AcceptNegative="Left" ErrorTooltipEnabled="True" />

      <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtAccidentDate"
            Display="None" ErrorMessage="Please select  Accident Date" ValidationGroup="Insured"
            SetFocusOnError="true">
        </asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtAccidentDate"
            ValidationGroup="Insured" Display="None" ErrorMessage="Please Enter valid Date"
            SetFocusOnError="true" ValidationExpression="(((0?[1-9]|1[012])[/.](0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])[/.](29|30)|(0?[13578]|1[02])/31)[/.](19|[2-9]\d)\d{2}|0?2[/.]29[/.]((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))">
        </asp:RegularExpressionValidator>
        <asp:ValidatorCalloutExtender ID="ValidatorCalloutExtender5" runat="server" Enabled="True"
            TargetControlID="RegularExpressionValidator1">
                                        </asp:ValidatorCalloutExtender>
        <asp:ValidatorCalloutExtender ID="ValidatorCalloutExtender6" runat="server" Enabled="True"
            TargetControlID="RequiredFieldValidator1">
                                        </asp:ValidatorCalloutExtender>
        <asp:CalendarExtender ID="CalendarExtender2" runat="server" Enabled="True" PopupButtonID="imgcal"
            format="MM/dd/yyyy" TargetControlID="txtAccidentDate" />
        <asp:ImageButton ID="imgcal" runat="server" CausesValidation="false" ImageUrl="~/Images/Calendar.png" />
        <span class="helpInformantion">(mm/dd/yyyy)</span>

答案 1 :(得分:0)

您必须编写代码以将选定的日历日期设置为文本框。 您可以通过在日历 SelectionChanged 事件

上编写代码来实现此目的

您的代码应该是

 protected void calendarextender_SelectionChanged(object sender, EventArgs e)
 {
   txtAccidentDate.text = calendarextender.SelectedDate;
 }

此处日历扩展程序是扩展程序的ID。