当用户点击页面上的Add
按钮时,我需要重复一些字段(文本框)Web表单UI。最初,他们看到一个控件只有很少的字段,当他们点击添加时,另一组相同的字段将被添加到页面。
所以我用户控制了重复的UI,当用户点击页面上的添加按钮时,我试图动态生成文本框并将其添加到页面。
但由于某种原因,我的动态生成的UI不可见。我相信这可能是一个观点国家问题。但不知道如何解决它。
这是我尝试使用用户控件的按钮点击方法添加到Usercontrol的更新面板的代码。
protected void AddBtn_Click(object sender, EventArgs e)
{
Panel panel = AddPanel(this.NumberOfDynamicControls);
AddVRMOrSink(panel, this.NumberofTextBoxes, this.NumberOfDynamicControls);
this.NumberOfDynamicControls++; // update number of controls
}
private void AddVRMOrSink(Panel panel, int textboxCounter, int i)
{
string[] labels = this.DisplayNames.Split('_');
TableRow tRow1 = new TableRow();
TableRow tRow2 = new TableRow();
TableRow tRow3 = new TableRow();
TableRow tRow4 = new TableRow();
tRow1.Width = new Unit(350, UnitType.Pixel);
tRow2.Width = new Unit(350, UnitType.Pixel);
tRow3.Width = new Unit(350, UnitType.Pixel);
tRow4.Width = new Unit(350, UnitType.Pixel);
TableCell cell1 = new TableCell();
TableCell cell2 = new TableCell();
TableCell cell21 = new TableCell();
TableCell cell22 = new TableCell();
TableCell cell31 = new TableCell();
TableCell cell32 = new TableCell();
TableCell cell41 = new TableCell();
TableCell cell42 = new TableCell();
tRow1.Cells.Add(cell1);
tRow1.Cells.Add(cell2);
tRow2.Cells.Add(cell21);
tRow2.Cells.Add(cell22);
tRow3.Cells.Add(cell31);
tRow3.Cells.Add(cell32);
tRow4.Cells.Add(cell41);
tRow4.Cells.Add(cell42);
TextBox txt_1 = AddTextBox(textboxCounter++, true);
TextBox txt_2 = AddTextBox(textboxCounter++);
TextBox txt_3 = AddTextBox(textboxCounter++);
TextBox txt_4 = AddTextBox(textboxCounter++);
TextBox txt_5 = AddTextBox(textboxCounter++);
Label lbl_1 = AddLabel(labels[0]);
Label lbl_2 = AddLabel(labels[1]);
Label lbl_3 = AddLabel(labels[2]);
Label lbl_4 = AddLabel(labels[3]);
Label lbl_5 = AddLabel(labels[4]);
Button deleteButton = AddDeleteButton(i + 1);
cell1.Controls.Add(lbl_1);
cell1.Controls.Add(txt_1);
cell2.Controls.Add(lbl_2);
cell2.Controls.Add(txt_2);
cell22.Controls.Add(lbl_3);
cell22.Controls.Add(txt_3);
cell32.Controls.Add(lbl_4);
cell32.Controls.Add(txt_4);
cell42.Controls.Add(lbl_5);
cell42.Controls.Add(txt_5);
panel.Controls.Add(tRow1);
panel.Controls.Add(tRow2);
panel.Controls.Add(tRow3);
panel.Controls.Add(tRow4);
panel.Controls.Add(deleteButton);
this.ControlsTable.Rows.Add(tRow1);
this.ControlsTable.Rows.Add(tRow2);
this.ControlsTable.Rows.Add(tRow3);
this.ControlsTable.Rows.Add(tRow4);
if (!isVRM)
{
Label lbl_6 = AddLabel(labels[5]);
TextBox txt_6 = AddTextBox(textboxCounter++);
TableRow tRow5 = new TableRow();
tRow5.Width = new Unit(350, UnitType.Pixel);
TableCell cell51 = new TableCell();
TableCell cell52 = new TableCell();
TableCell cell53 = new TableCell();
cell52.Controls.Add(lbl_6);
cell52.Controls.Add(txt_6);
cell53.Controls.Add(deleteButton);
tRow5.Cells.Add(cell51);
tRow5.Cells.Add(cell52);
tRow5.Cells.Add(cell53);
panel.Controls.Add(tRow5);
this.ControlsTable.Rows.Add(tRow5);
}
else
{
TableCell cell43 = new TableCell();
cell43.Controls.Add(deleteButton);
tRow4.Cells.Add(cell43);
}
UpdatePanel1.ContentTemplateContainer.Controls.Add(panel);
DynamicControlPlaceHolder.Controls.Add(panel);
}
usercontrol.ascx是
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="GenericVRMSINKControl.ascx.cs"
Inherits="ABC.UI.UserControls.RequestControls.GenericVRMSINKControl" %>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:HiddenField ID="numberOfControls" Value="1" EnableViewState="true" runat="server" />
<asp:PlaceHolder ID="DynamicControlPlaceHolder" runat="server">
<asp:Panel ID="staticControlsPanel" runat="server">
<asp:Table Width="100%" runat="server" ID="ControlsTable">
<asp:TableRow Style="width: 350px">
<asp:TableCell>
<asp:Label runat="server" Text="" ID="PinNos" EnableTheming="false" Width="110pt">
</asp:Label>
<asp:TextBox ID="txt_PinNos" runat="server" Width="140pt" TextMode="MultiLine">
</asp:TextBox>
</asp:TableCell>
<asp:TableCell>
<asp:Label runat="server" Text="" ID="FieldNameLabel1" EnableTheming="false" Width="110pt">
</asp:Label>
<asp:TextBox ID="FieldValueTextBox1" runat="server" Width="140pt">
</asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow Style="width: 350px">
<asp:TableCell>
</asp:TableCell>
<asp:TableCell>
<asp:Label runat="server" Text="" ID="FieldNameLabel2" EnableTheming="false" Width="110pt">
</asp:Label>
<asp:TextBox ID="FieldvalueTextBox2" runat="server" Width="140pt">
</asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow Style="width: 350px">
<asp:TableCell>
</asp:TableCell>
<asp:TableCell>
<asp:Label runat="server" Text="" ID="FieldNameLabel3" EnableTheming="false" Width="110pt">
</asp:Label>
<asp:TextBox ID="FieldvalueTextBox3" runat="server" Width="140pt">
</asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow Style="width: 350px">
<asp:TableCell>
</asp:TableCell>
<asp:TableCell>
<asp:Label runat="server" Text="" ID="FieldNameLabel4" EnableTheming="false" Width="110pt">
</asp:Label>
<asp:TextBox ID="FieldvalueTextBox4" runat="server" Width="140pt">
</asp:TextBox>
</asp:TableCell>
<asp:TableCell>
<asp:Button ID="addBtn" runat="server" CausesValidation="False" OnClick="AddBtn_Click" Text="Add" Width="66px" Height="26px" Visible="true" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:Panel>
</asp:PlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
&#13;
我对这里遗失的内容有任何想法吗?