文本框未设置为模态弹出扩展器中的值

时间:2012-09-20 09:06:17

标签: c# asp.net asp.net-ajax

我正在使用一个模态弹出扩展器,它包含一个有三个文本框和两个按钮的面板。我想用我的规范(所选日期)填充文本框值..但不能成功。

protected void myCal_SelectionChanged(object sender, EventArgs e)
    {
        ModalPopupExtender1.Show();
        TextBoxStart.Text = myCal.SelectedDate.ToString();
        TextBoxEnd.Text = myCal.SelectedDate.ToString();
    }

设计师

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">

  <ContentTemplate>        
      <asp:Calendar ID="myCal" runat="server" Height="600px" width="900px" 
        BorderColor="#F2F3F4" BorderWidth="3px" DayStyle-BorderWidth="1px" 
                TodayDayStyle-BackColor="#82CAFF" NextPrevFormat="ShortMonth" 
        SelectionMode="Day" DayHeaderStyle-Height="30px" 
                TitleStyle-BackColor="#CBE3F0" TitleStyle-ForeColor="#153E7E" 
        OtherMonthDayStyle-ForeColor="#B4CFEC" NextPrevStyle-ForeColor="#2554C7" 
        CssClass="mGrid" onselectionchanged="myCal_SelectionChanged">
        <DayHeaderStyle Height="30px" /><TitleStyle Height="50px" />
        <DayStyle BorderWidth="1px" HorizontalAlign="Left" VerticalAlign="Top" />
        <TodayDayStyle BackColor="#CBE3F0" />
    </asp:Calendar>

      <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="ButtonDummy" PopupControlID="pnlSelect">

      </ajaxToolkit:ModalPopupExtender>

</ContentTemplate>

      </asp:UpdatePanel>


    <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Always">
<ContentTemplate>

       <asp:Panel ID="pnlSelect" runat="server" width="200px" Height="200px">

           <table border="0" cellspacing="6" cellpadding="0" style="background-color: white">
               <tr>
                   <td align="right"></td>
                   <td>
                       <h2>New Appointment</h2>
                   </td>
               </tr>
               <tr>
                   <td align="right">Start Date:</td>
                   <td>
                       <asp:TextBox ID="TextBoxStart" runat="server"></asp:TextBox></td>
               </tr>
               <tr>
                   <td align="right">End Date:</td>
                   <td>
                       <asp:TextBox ID="TextBoxEnd" runat="server"></asp:TextBox></td>
               </tr>
               <tr>
                   <td align="right">Name:</td>
                   <td>
                       <asp:TextBox ID="TextBoxName" runat="server"></asp:TextBox></td>
               </tr>
               <tr>
                   <td align="right"></td>
                   <td>
                       <asp:Button ID="ButtonOK" runat="server" OnClick="ButtonOK_Click" Text="OK" />
                       <asp:Button ID="ButtonCancel" runat="server" Text="Cancel" OnClick="ButtonCancel_Click" />
                   </td>
               </tr>
           </table>

       </asp:Panel>
    </ContentTemplate>

有什么不对?

1 个答案:

答案 0 :(得分:2)

由于这些文本框放在UpdatePanel之外,因此它们不会在异步请求中更新。将它们放入同一个UpdatePanel或由另一个UpdatePanel包装,并将UpdateMode设置为“Always”,如下所示:

<asp:UpdatePanel runat="server" UpdateMode="Always">
    <ContentTemplate>
        <asp:Panel runat="server" ID="pnlSelect" >
            <asp:TextBox runat="server" ID="TextBoxStart" />
            <asp:TextBox runat="server" ID="TextBoxEnd" />
        </asp:Panel>
    </ContentTemplate>
</asp:UpdatePanel>

尝试将UpdatePanel1的ChildrenAsTriggers属性设置为true或将ModalPopupExtender1移至UpdatePanel2。

此外,您可以将PopupExtender及其目标虚拟按钮移出UpdatePanel1并使用UpdatePanel2交换pnlSelect:

<asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional" ChildrenAsTriggers="false">
    <ContentTemplate>
        <asp:Button ID="Button1" runat="server" Text="Click Me" />
    </ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="ButtonDummy" runat="server" Style="display: none" />
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="ButtonDummy"
    PopupControlID="pnlSelect" BackgroundCssClass="modalBackground" />
<asp:Panel ID="pnlSelect" runat="server" Style="display: none" CssClass="modalPopup">
    <asp:UpdatePanel runat="server" ID="UpdatePanel2" UpdateMode="Always">
        <ContentTemplate>
            <asp:TextBox runat="server" ID="TextBoxStart" />
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Panel>