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

Problem with RenderControl

5 Answers 250 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
M Amin
Top achievements
Rank 1
M Amin asked on 24 Feb 2010, 06:47 AM
Hello everyone

I am trying to create dynamic RadComboBox in my Ajax request, and then sending back as html, for this i am using RenderControl for the  RadComboBox control. but I get this error when it executes the RenderControl method ...

new ajax_error('System.InvalidOperationException','Page cannot be null. Please ensure that this operation is being performed in the context of an ASP.NET request.',0)

Here is the code snippet 

	
Dim sb As New StringBuilder 
        Dim sw As New System.IO.StringWriter(sb) 
        Dim hw As New HtmlTextWriter(sw) 
 
        Dim ddlCountries As New Telerik.Web.UI.RadComboBox 
        ddlCountries.ID = "ddlCountries" 
        Dim loc As New Frokht.Location 
        Dim dr As Data.SqlClient.SqlDataReader 
 
        dr = loc.GetAllCountries() 
        ddlCountries.DataSource = dr 
        ddlCountries.DataTextField = "Name" 
        ddlCountries.DataValueField = "Code" 
        ddlCountries.DataBind() 
ddlCountries.RenderControl(hw)


Please help

Thanks in advance


5 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 03 Mar 2010, 11:38 AM
Hi M Amin,

This error raises because the RadComboBox is not added to the Page control hierarchy.

You can add the control directly to the Form or some other container (in the page), e.g.

Form.Controls.Add(ddlCountries)

All the best,
Simon
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
M Amin
Top achievements
Rank 1
answered on 08 Mar 2010, 06:31 AM
Hi Simon
Thanks for your help, but now i am getting another error.

Script control 'countries' is not a registered script control. Script controls must be registered using RegisterScriptControl() before calling RegisterScriptDescriptors().

i tried ScriptManager1.RegisterScriptControl(ddlCountries) before RenderControl, but it then gave me error Script controls may not be registered before PreRender.

Please help.
0
Simon
Telerik team
answered on 09 Mar 2010, 06:13 PM
Hello M Amin,

This can happen if you are calling RenderControl too early in the page life cycle. 

The best way to approach this is to only add the control in the Init phase or later if a certain postback condition should be met and leave the control to the ASP.NET framework. It will call the control's respective methods and will register it whenever necessary.

Kind regards,
Simon
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
M Amin
Top achievements
Rank 1
answered on 11 Mar 2010, 05:25 AM
I am trying to create a dynamic control in an AJAX request, I did not understand "if a certain postback condition should be met and leave the control to the ASP.NET framework. It will call the control's respective methods and will register it whenever necessary." Can you please explain
Thanks
0
Simon
Telerik team
answered on 11 Mar 2010, 03:04 PM
Hi M Amin,

What I meant was that you only need to add the Control to the page control hierarchy. In the render phase, the Render methods of all controls will be called automatically as well as their scripts registered. In other words you do not need to these things this manually.

Finally I suggest you try a different approach: add the RadComboBox to the page initially invisible and toggle its Visible property instead.

Best wishes,
Simon
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
General Discussions
Asked by
M Amin
Top achievements
Rank 1
Answers by
Simon
Telerik team
M Amin
Top achievements
Rank 1
Share this question
or