Error while creating dynamic RadButton

2 posts, 0 answers
  1. Balaji
    Balaji avatar
    1 posts
    Member since:
    Jun 2012

    Posted 25 Jul 2012 Link to this post

    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

            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
            Dim stringBuilder As New StringBuilder()
            Dim stringWriter As New StringWriter(stringBuilder)
            Dim textWriter As New HtmlTextWriter(stringWriter)
  2. Slav
    Slav avatar
    1359 posts

    Posted 27 Jul 2012 Link to this post

    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:

    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,
    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.
Back to Top