Control Creation Error - User Control

I have a custom control and it works great ... except that the control cannot be displayed at design time. (I am using VS 2008)

I think that many people who develop custom controls face this problem ... The error I get is the "Error creating control - CustomControlName". The reference to the object is not installed in the instance of the object.

I want to work. or at least debug it ... (Since it is a matter of development time, how to debug it?)

I tried using the code (! DesignMode) in OnInit, OnPreRender, RenderContents, CreateChildControls Methods (I just shoot in the dark) ...

Help pls. I really hope this is not a VS error!

+3
source share
4 answers

BFree's comment is the most likely problem: for the control displayed in the project view, it needs a constructor without parameters, because the design viewer does not know how you usually create an instance of the control.

If you have a constructor without parameters, can you paste the code to show what is happening?

+1
source

As Glenn said, the first problem cannot be without a constructor without parameters.

-, OnLoad , , - .., .

*, , , DesignMode , , , . (, , UserControl [1], UserControl [2], DesignMode [1], [2]).

, , .

* .

0

OnPreRender CreateChildControls this.Page.

if (this.Page != null)
{
.....
}

Because I do not think that you will have a page object at this moment, and I am sure that PreRenderthey CreateChildControlswill be called in the design view. For some time I did not write user server controls, so I could be wrong (I have been working in MVC lately).

0
source

Glenn, ur error getting VS error, and hotfix not yet released.

0
source

All Articles