Dynamically added HTMLTableCells not being "stored" on web page

2 posts, 0 answers
  1. hkdave95
    hkdave95 avatar
    245 posts
    Member since:
    Nov 2006

    Posted 19 Dec 2007 Link to this post

    Hi

    I am dynamically adding HtmlTableCells to my WebUserControl within a RadGrid within a RadAjaxPanel.

    However, when I come to access those dynamically added HtmlTableCells by clicking the Update button on my WebUserControl, and using the FindControl method I get a server side error. Null Object.

    NB: The rendering code works fine. The object are displayed onthe screen wiithout any problems.

    My rendering code is thus ....

    For lnCount = 0 To 9
                                If System.IO.File.Exists(Me.Server.MapPath("../images/stock/" & loStockRow.S_nId.ToString("00000000") & "_" & lnCount.ToString("00") & ".jpg")) Then
                                    Dim loTableCell As New HtmlTableCell
                                    loTableCell.ID = "tdImage" & lnCount.ToString("00")
                                    Dim loCheckBox As New CheckBox
                                    loCheckBox.ID = "bImage" & lnCount.ToString("00")
                                    loCheckBox.Text = "Delete"
                                    Call loTableCell.Controls.Add(loCheckBox)
                                    Call Me.trImages2.Cells.Add(loTableCell)
                                End If
                            Next lnCount

    And the code I am using to access the object I have added is thus...

                    For lnCount = 0 To 9
                        If System.IO.File.Exists(Me.Server.MapPath("../images/stock/" & loStockRow.S_nId.ToString("00000000") & "_" & lnCount.ToString("00") & ".jpg")) Then
                            If Me.trImages2.FindControl("tdImages" & lnCount.ToString("00")) IsNot Nothing AndAlso Me.trImages2.FindControl("tdImages" & lnCount.ToString("00")).FindControl("bImage" & lnCount.ToString("00")) IsNot Nothing Then
                                If CType(Me.trImages2.FindControl("tdImages" & lnCount.ToString("00")).FindControl("bImage" & lnCount.ToString("00")), CheckBox).Checked Then
                                    Call System.IO.File.Delete(Me.Server.MapPath("../images/stock/" & loStockRow.S_nId.ToString("00000000") & "_" & lnCount.ToString("00") & ".jpg"))
                                End If
                                lnCount2 += 1
                            End If
                        End If
                    Next lnCount

    NB: The Count from the trImages object is zero. Unless I access the object immediatelyy after I have added the controls.

    Kind Regards

    David
  2. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 20 Dec 2007 Link to this post

    Hi hkdave95,

    The cause of the problem you are facing most probably is due to not recreating control's hierarchy. As when adding controls in control's tree after page's load event completes (for example on itemCommand event handler) you will have to re-add them  in control's collection on every subsequent postback.

    You can review the following article for more information about adding controls dynamically.

    Sincerely yours,
    Rosen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top