在模态弹出面板中添加文本框

本文关键字:添加 文本 模态 | 更新日期: 2023-09-27 18:11:09

如何在模态弹出框中动态地向面板添加文本框?我正在尝试这个到目前为止没有运气....

有一个网格视图,弹出一个模态面板,我想动态添加文本框。

FOR循环的更新代码:

int num = 4;
int I;
// Create TB's
for (I = 1; I <= num; I++)
{
        Panel newPanel = (Panel)Page.Master.FindControl("pnlpopup");
        PlaceHolder MainContent2 = (PlaceHolder)newPanel.FindControl("PlaceHolder3");
        TextBox txtB = new TextBox();
        txtB.ID = "txtBEdit" + I.ToString("D2");
        MainContent2.Controls.Add(txtB);
}
this.ModalPopupExtender.Show();here

这是aspx.

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
<title>Untitled Page</title>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<asp:ModalPopupExtender ID="ModalPopupExtender" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlpopup" CancelControlID="btnCancel" BackgroundCssClass="modalBackground">
</asp:ModalPopupExtender>
<asp:Label ID="lblresult" runat="server"/>
<asp:Button ID="btnShowPopup" runat="server" style="display:none" />
<asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="650px" 
    Width="500px" Font-Size="Small">
<table width="100%" style="border:Solid 3px #D55500; width:100%; height:100%" cellpadding="1" cellspacing="1">
    <tr style="background-color:#D55500">
    <td colspan="2" style=" height:10%; color:White; font-weight:bold; font-size:larger" align="center">Foreign Text Input</td>
    </tr>
    <tr>
        <td align="left" style=" width:20%">ID:
        </td>
        <td>
            <asp:Label ID="lblID" runat="server"></asp:Label>
        </td>
    </tr>
    <tr>
        <td align="left">English text:
        </td>
        <td>
           <asp:Label ID="data_text" runat="server"></asp:Label>
        </td>
    </tr>
    <tr>
        <td>
        <asp:PlaceHolder ID="PlaceHolder3" runat="server"></asp:PlaceHolder>

        <!--Textboxes will be added here -->

        </td>
    </tr>
    <tr>
        <td>
        </td>
        <td>
            <asp:Button ID="btnUpdate" CommandName="Update" runat="server" Text="Update" onclick="btnUpdate_Click"/>
            <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
        </td>
    </tr>
</table>
</asp:Panel>
</div>
</asp:Content>

为了提供解决方案,我添加了下面的代码行....

PlaceHolder MainContent2 = (PlaceHolder)PlaceHolder3.FindControl("PlaceHolder3");

在模态弹出面板中添加文本框

因为PlaceHolder3是一个

<asp:PlaceHolder ID="PlaceHolder3" runat="server"></asp:PlaceHolder>

你应该可以通过这个访问它。直接PlaceHoder3。如果没有,则添加

protected PlaceHolder PlaceHolder3;