我该如何在模态弹出框中动态添加文本框到面板中?我尝试了以下代码,但是没有成功...
有一个网格视图会弹出一个模态面板,在这个面板中我想要动态添加文本框。
循环中更新的代码:
为了提供解决方案,我添加了以下代码行......
有一个网格视图会弹出一个模态面板,在这个面板中我想要动态添加文本框。
循环中更新的代码:
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");