This is a migrated thread and some comments may be shown as answers.

Dynamically added HTMLTableCells not being "stored" on web page

1 Answer 35 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
hkdave95
Top achievements
Rank 2
hkdave95 asked on 20 Dec 2007, 01:54 AM
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

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 20 Dec 2007, 12:44 PM
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
Tags
Ajax
Asked by
hkdave95
Top achievements
Rank 2
Answers by
Rosen
Telerik team
Share this question
or