I have a problem with my user control. Inside I have a checkbox. I want to create this user control on the fly and paste it into asp: table control.
MyControl pp = new MyControl(); pp.pageNameCb.Text = "lorem"; TableCell tc = new TableCell(); tc.Controls.Add(pp); table.Rows[0].Cells.Add(tc);
But pageNameCb
is null, even if I create it manually, nothing is displayed in my table. Why?
Here is my code:
<asp:View ID="new_role_view" runat="server"> <asp:Table ID="table1" runat="server"> <asp:TableRow ID="TableRow1" runat="server"> <asp:TableCell ID="TableCell1" runat="server"> </asp:TableCell> </asp:TableRow> </asp:Table> </asp:View>
Then, if I change this view, I create my control:
MyControl pp = new MyControl(); table.Rows[0].Cells[0].Controls.Add(pp);
MyControl Page_Init:
protected void Page_Init(object sender, EventArgs e) { if (pageNameCb == null) pageNameCb = new CheckBox(); pageNameCb.Text = "works"; }
and yet shows nothing
source share