Not running init code at design time

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello all

I am writing a Web Custom Control that extends the CheckboxList control

For performance reasons I do some one-time resource management in the (static) constructor. This requires access to the Server object, which is not available at design time. Therefore, when I drop the control on a web form, I get "error creating control"

Someone suggested creating a custom designer to provide a different interface at design time. I tried that but the problem is that the component is instantiated first and then passed to my designer class, meaning that the problem occurs before my designer can do anything about it

How can I get some code in my constructor to not run at design time

Clarenc
 
Clarence,

You can detect whether the code is running in design mode by verifying
whether there is a current HttpContext. e.g.:

protected bool DesignMode
{
get
{
return HttpContext.Current == null;
}
}

HTH,
Nicole
 
Back
Top