Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Not able to read the dynamic controls

Not able to read the dynamic controls

Scheduled Pinned Locked Moved ASP.NET
sysadminhelpannouncement
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rajasreepradeep
    wrote on last edited by
    #1

    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.

    G 1 Reply Last reply
    0
    • R rajasreepradeep

      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.

      G Offline
      G Offline
      Gayani Devapriya
      wrote on last edited by
      #2

      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

      R 1 Reply Last reply
      0
      • G Gayani Devapriya

        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

        R Offline
        R Offline
        rajasreepradeep
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups