在模态弹出窗口中向文本框添加文本框

时间:2011-10-12 15:20:56

标签: c# javascript asp.net

如何在模式弹出窗口中动态地将文本框添加到Panel?到目前为止,我正在尝试这个没有运气....

有一个gridview弹出一个模态面板,我想动态添加文本框。

循环更新代码:

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");

1 个答案:

答案 0 :(得分:2)

由于PlaceHolder3是

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

您应该可以直接通过this.PlaceHoder3访问它。如果没有,那么添加

protected PlaceHolder PlaceHolder3;

到您的班级定义。