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

Error while creating dynamic RadButton

1 Answer 30 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Balaji
Top achievements
Rank 1
Balaji asked on 25 Jul 2012, 07:18 AM
In the below method when the execution came to   tbData.RenderControl(textWriter)  method ,then it is giving an error as "Page cannot be null. Please ensure that this operation is being performed in the context of an ASP.NET request."

Dim sb As New StringBuilder
        Dim tbData As New HtmlTable
        Dim Row As New HtmlTableRow
        Dim add_img_popup As New RadButton()
        add_img_popup.Text = "Add new Image"
        ' click event handler
        add_img_popup.Enabled = True
        add_img_popup.ID = "btn_add_img_popup"
        ' programmatic id
        ' Page.Controls.Add(add_img_popup)
        Dim CellTopicID As New HtmlTableCell
        CellTopicID.Style.Add("font-family", "Arial")
        CellTopicID.Style.Add("font-size", "10pt")
        CellTopicID.VAlign = "Top"
        CellTopicID.Align = "Left"
        CellTopicID.NoWrap = False
        CellTopicID.Controls.Add(add_img_popup)
        Row.Cells.Add(CellTopicID)


        Dim CellDateNotified As New HtmlTableCell
        CellDateNotified.InnerText = "Hello"
        CellDateNotified.Style.Add("font-family", "Arial")
        CellDateNotified.Style.Add("font-size", "10pt")
        CellDateNotified.VAlign = "Top"
        CellDateNotified.Align = "Left"
        CellDateNotified.NoWrap = True
        Row.Cells.Add(CellDateNotified)
        tbData.Rows.Add(Row)
        Dim stringBuilder As New StringBuilder()
        Dim stringWriter As New StringWriter(stringBuilder)
        Dim textWriter As New HtmlTextWriter(stringWriter)
        tbData.RenderControl(textWriter)

1 Answer, 1 is accepted

Sort by
0
Slav
Telerik team
answered on 27 Jul 2012, 10:03 AM
Hello Balaji,

The problem you encountered occurs because the HtmlTable tbData is not included in the page when you call its method RenderControl. You should add the following line:
Form.Controls.Add(tbData)

The RenderControl method is designed for use in scenarios that do not include the page's lifecycle. Usually when an ASP control in added on a page, the lifecycle takes care of its rendering as shown and calls RenderControl as described in this article. In case there is a reason to call this method explicitly, please describe it so that I can help you accordingly.

All the best,
Slav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
General Discussions
Asked by
Balaji
Top achievements
Rank 1
Answers by
Slav
Telerik team
Share this question
or