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

[Solved] Error with WebControl

4 Answers 129 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
CYFL
Top achievements
Rank 1
CYFL asked on 17 Feb 2010, 10:53 AM

Hello,

I start with Telerik, and i woul'd like to put Telerik controls into webcontrol.
i have try many solution, but no one display me the result in the design mode.
I have an error : "Error Creating Control " "Object reference not set to an instance of an object."
but when I run the webpage, i see my Telerik control.

do you have an idea for this problems ?

my code :
Public Class Class11 
    Inherits System.Web.UI.WebControls.WebControl 
 
    Protected WithEvents RadComboBox2 As Global.Telerik.Web.UI.RadComboBox 
 
 Public Sub New() 
        MyBase.new() 
        RadComboBox2 = New Telerik.Web.UI.RadComboBox 
        RadComboBox2.ID = "toto" 
    End Sub 
 
Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter) 
 
        RadComboBox2.RenderControl(output) 
        MyBase.CreateChildControls() 
    End Sub 
 
 Protected Overrides Sub CreateChildControls() 
        Me.Controls.Clear() 
        Me.Controls.Add(RadComboBox2) 
 
    End Sub 
 
 

thanks a lot !!!

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 17 Feb 2010, 12:27 PM
Hello,

Please examine the following blog post:
http://blogs.telerik.com/atanaskorchev/posts/09-03-06/Meet_Telerik_Web_Design_dll.aspx

Regards,
Daniel
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
CYFL
Top achievements
Rank 1
answered on 17 Feb 2010, 01:20 PM
Hello

I try the propose solutions, but it does not work better,
I have always the error

: (

0
CYFL
Top achievements
Rank 1
answered on 18 Feb 2010, 01:17 PM
nobody has never tested this mode?
:(
0
Accepted
Daniel
Telerik team
answered on 22 Feb 2010, 03:37 PM
Hello,

This error is caused due to the fact that RadComboBox is not yet added to the Controls collection of your custom control. RadComboBox is not aware that it is in design mode and it tries to render itself as it was on the page. To sidestep this problem, I recommend you call EnsureChildControls before calling the render method. Of course, this is not needed when your control is not in design mode.

public class MyControl : WebControl
{
    RadComboBox combo;
    public MyControl()
    {
        combo = new RadComboBox();
        combo.ID = "Test";
    }
 
    protected override void Render(System.Web.UI.HtmlTextWriter writer)
    {
        base.Render(writer);
 
        if (DesignMode)
        {
            EnsureChildControls();
            combo.RenderControl(writer);
        }
    }
 
    protected override void CreateChildControls()
    {
        Controls.Clear();
        Controls.Add(combo);
    }
}

Kind regards,
Daniel
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
CYFL
Top achievements
Rank 1
Answers by
Daniel
Telerik team
CYFL
Top achievements
Rank 1
Share this question
or