Not able to read the dynamic controls
-
Hi, I have created some dynamic controls in page load and added to an existing asp:Table Its displaying in the page ( the page contains 3 tabs , this controls are added in one of the tab) If I click on another tab , I am trying to save the data in this dynamic controls . But not able to access it. Code This panel is a part of one table. <asp:Panel ID="pStudySpecific" runat="server" EnableViewState="true" > <%--<table width="100%" > --%> <tr> <td> <asp:Table width="100%" border="1" runat="server" id="tblTimeZone" enableviewstate="true" > asp:TableRow asp:TableCell <asp:Table ID="tblTimeZones" runat="server" border="0" EnableViewState="true" > <asp:TableHeaderRow HorizontalAlign="Left"> <asp:TableHeaderCell HorizontalAlign="Left"> <asp:Label runat="server" ID="lblTimeZoneDetails" Text="TimeZone" SkinID="GroupTitleSkin"></asp:Label> </asp:TableHeaderCell> </asp:TableHeaderRow> </asp:Table> </asp:TableCell> </asp:TableRow> </asp:Table> </td> </tr> </panel> 1. page load create controls and added to tblTimeZones. 2.Tab( link button click event) I tried to access control ContentPlaceHolder cphDetails = (ContentPlaceHolder)this.Master.FindControl("cphDetails"); Table tblTimeZon = (Table)cphDetails.FindControl("tblTimeZones"); till here its fine ,I am getting the values. DropDownList drpLstControl = (DropDownList)tblTimeZon.FindControl("drpLst" + objCustomField.DatabaseField); In the above line its giving null value. This all controls are in an update panel and content place holder. Please help.
-
Hi, I have created some dynamic controls in page load and added to an existing asp:Table Its displaying in the page ( the page contains 3 tabs , this controls are added in one of the tab) If I click on another tab , I am trying to save the data in this dynamic controls . But not able to access it. Code This panel is a part of one table. <asp:Panel ID="pStudySpecific" runat="server" EnableViewState="true" > <%--<table width="100%" > --%> <tr> <td> <asp:Table width="100%" border="1" runat="server" id="tblTimeZone" enableviewstate="true" > asp:TableRow asp:TableCell <asp:Table ID="tblTimeZones" runat="server" border="0" EnableViewState="true" > <asp:TableHeaderRow HorizontalAlign="Left"> <asp:TableHeaderCell HorizontalAlign="Left"> <asp:Label runat="server" ID="lblTimeZoneDetails" Text="TimeZone" SkinID="GroupTitleSkin"></asp:Label> </asp:TableHeaderCell> </asp:TableHeaderRow> </asp:Table> </asp:TableCell> </asp:TableRow> </asp:Table> </td> </tr> </panel> 1. page load create controls and added to tblTimeZones. 2.Tab( link button click event) I tried to access control ContentPlaceHolder cphDetails = (ContentPlaceHolder)this.Master.FindControl("cphDetails"); Table tblTimeZon = (Table)cphDetails.FindControl("tblTimeZones"); till here its fine ,I am getting the values. DropDownList drpLstControl = (DropDownList)tblTimeZon.FindControl("drpLst" + objCustomField.DatabaseField); In the above line its giving null value. This all controls are in an update panel and content place holder. Please help.
Hi, One important thing i noticed was you need to traverse through rows and then cells in tblTimeZon table. And then try to find the control in a particular cell. Here is a small example, i will be using a TextBox. .aspx code <asp:Table ID="Table1" runat="server" Height="160px" Width="176px"> <asp:TableRow runat="server" ID="ROW1"> <asp:TableCell runat="server" ID="CELL1"> aaa <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </asp:TableCell> <asp:TableCell runat="server">bbb</asp:TableCell> <asp:TableCell runat="server">ccc</asp:TableCell> </asp:TableRow> </asp:Table> <asp:Button ID="Button1" runat="server" Text="Get Content in Text" OnClick="Button1_Click" /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> .cs code protected void Button1_Click(object sender, EventArgs e) { foreach (TableRow tr in Table1.Rows) { foreach (TableCell tc in tr.Cells) { TextBox tb = (TextBox)tc.FindControl("TextBox1"); if(tb != null) { Label1.Text = tb.Text; } } } } Hope it helped. Thx, Gayani
-
Hi, One important thing i noticed was you need to traverse through rows and then cells in tblTimeZon table. And then try to find the control in a particular cell. Here is a small example, i will be using a TextBox. .aspx code <asp:Table ID="Table1" runat="server" Height="160px" Width="176px"> <asp:TableRow runat="server" ID="ROW1"> <asp:TableCell runat="server" ID="CELL1"> aaa <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> </asp:TableCell> <asp:TableCell runat="server">bbb</asp:TableCell> <asp:TableCell runat="server">ccc</asp:TableCell> </asp:TableRow> </asp:Table> <asp:Button ID="Button1" runat="server" Text="Get Content in Text" OnClick="Button1_Click" /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> .cs code protected void Button1_Click(object sender, EventArgs e) { foreach (TableRow tr in Table1.Rows) { foreach (TableCell tc in tr.Cells) { TextBox tb = (TextBox)tc.FindControl("TextBox1"); if(tb != null) { Label1.Text = tb.Text; } } } } Hope it helped. Thx, Gayani
thaks for the reply , But i am adding 4 rows in to the table,after postback( link button click ) no rows are there in the table. The controls are lost. Please help.