1

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

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>

有什么问题?

4

1 回答 1

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>

尝试将ChildrenAsTriggersUpdatePanel1 的属性设置为true或将 ModalPopupExtender1 移动到 UpdatePanel2。

此外,您可以将 PopupExtender 和他的目标虚拟按钮移出 UpdatePanel1 并将 pnlSelect 与 UpdatePanel2 交换:

<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>
于 2012-09-20T10:13:25.927 回答