PC Review


Reply
Thread Tools Rate Thread

How can I tell if I am running in design mode?

 
 
newscorrespondent@charter.net
Guest
Posts: n/a
 
      14th Jul 2006

What is the "if" to tell if my code is running in design mode?

Thanks
 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      14th Jul 2006
Your component has to be derived from the Component class. From that,
you can check the DesignMode property. If it is true, then you are in
design mode, false otherwise.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

<(E-Mail Removed)> wrote in message
news:FFStg.2076$(E-Mail Removed)...
>
> What is the "if" to tell if my code is running in design mode?
>
> Thanks



 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      14th Jul 2006
newscorrespondent,
Do you mean in ASP.NET as with a Custom Control on a page? If so, then the
HttpContext.Current will be null.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




"(E-Mail Removed)" wrote:

>
> What is the "if" to tell if my code is running in design mode?
>
> Thanks
>

 
Reply With Quote
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      14th Jul 2006
Peter,

That's not a good idea, IMO, since all classes that derive from Control
(in the System.Web.UI namespace) have a protected property called DesignMode
which exposes whether or not the control is hosted in the designer.


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"Peter Bromberg [C# MVP]" <(E-Mail Removed)> wrote in message
news:0603E4E0-9F0C-4407-89FE-(E-Mail Removed)...
> newscorrespondent,
> Do you mean in ASP.NET as with a Custom Control on a page? If so, then the
> HttpContext.Current will be null.
> Peter
>
> --
> Co-founder, Eggheadcafe.com developer portal:
> http://www.eggheadcafe.com
> UnBlog:
> http://petesbloggerama.blogspot.com
>
>
>
>
> "(E-Mail Removed)" wrote:
>
>>
>> What is the "if" to tell if my code is running in design mode?
>>
>> Thanks
>>



 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      14th Jul 2006
Nick,
This is true but it is not always a complete solution to the potential
problems exposed here. MVP Rick Strahl's blog post illustrates:

http://west-wind.com/weblog/posts/189.aspx

Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




"Nicholas Paldino [.NET/C# MVP]" wrote:

> Peter,
>
> That's not a good idea, IMO, since all classes that derive from Control
> (in the System.Web.UI namespace) have a protected property called DesignMode
> which exposes whether or not the control is hosted in the designer.
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - (E-Mail Removed)
>
> "Peter Bromberg [C# MVP]" <(E-Mail Removed)> wrote in message
> news:0603E4E0-9F0C-4407-89FE-(E-Mail Removed)...
> > newscorrespondent,
> > Do you mean in ASP.NET as with a Custom Control on a page? If so, then the
> > HttpContext.Current will be null.
> > Peter
> >
> > --
> > Co-founder, Eggheadcafe.com developer portal:
> > http://www.eggheadcafe.com
> > UnBlog:
> > http://petesbloggerama.blogspot.com
> >
> >
> >
> >
> > "(E-Mail Removed)" wrote:
> >
> >>
> >> What is the "if" to tell if my code is running in design mode?
> >>
> >> Thanks
> >>

>
>
>

 
Reply With Quote
 
Bruce Wood
Guest
Posts: n/a
 
      14th Jul 2006

Nicholas Paldino [.NET/C# MVP] wrote:
> Your component has to be derived from the Component class. From that,
> you can check the DesignMode property. If it is true, then you are in
> design mode, false otherwise.


I should add that DesignMode is set only after your control has a
context handle in the designer, so in your constructor code it will
always be false, whether you are in the designer or not.

If there is code that you don't want run in design mode then you should
put it in your OnLoad method, where the DesignMode property does have a
valid value.

 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      14th Jul 2006
Bruce,
The issue I've come across with this - beside the fact that the property
doesn't exist in the ASP.NET 1.1 Framework -- is that if you have a
ServerControl that relies on the HttpContext to render it's DesignTimeHtml
(such as making an HttpWebRequest) then it would blow up in the designer even
though functioning perfectly well at runtime. Rick's blog post which I
referenced below solves this problem.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




"Bruce Wood" wrote:

>
> Nicholas Paldino [.NET/C# MVP] wrote:
> > Your component has to be derived from the Component class. From that,
> > you can check the DesignMode property. If it is true, then you are in
> > design mode, false otherwise.

>
> I should add that DesignMode is set only after your control has a
> context handle in the designer, so in your constructor code it will
> always be false, whether you are in the designer or not.
>
> If there is code that you don't want run in design mode then you should
> put it in your OnLoad method, where the DesignMode property does have a
> valid value.
>
>

 
Reply With Quote
 
Bruce Wood
Guest
Posts: n/a
 
      14th Jul 2006
Peter wrote:
> The issue I've come across with this - beside the fact that the property
> doesn't exist in the ASP.NET 1.1 Framework -- is that if you have a
> ServerControl that relies on the HttpContext to render it's DesignTimeHtml
> (such as making an HttpWebRequest) then it would blow up in the designer even
> though functioning perfectly well at runtime. Rick's blog post which I
> referenced below solves this problem.


Sorry. I should have been more specific. I was talking WinForms.

 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      15th Jul 2006
Yep,
This is a constant problem here - people sometimes referring to ASP.NET
issues and not being explicit about it, and posting to the C# language group
because they are programming in C# (a good thing!) - and some even
programming in VB.NET (potentially also a good thing, with some provisos).
Cheers,
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




"Bruce Wood" wrote:

> Peter wrote:
> > The issue I've come across with this - beside the fact that the property
> > doesn't exist in the ASP.NET 1.1 Framework -- is that if you have a
> > ServerControl that relies on the HttpContext to render it's DesignTimeHtml
> > (such as making an HttpWebRequest) then it would blow up in the designer even
> > though functioning perfectly well at runtime. Rick's blog post which I
> > referenced below solves this problem.

>
> Sorry. I should have been more specific. I was talking WinForms.
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
code is running at design mode??? SS Microsoft Access 3 16th Aug 2007 10:45 AM
Webparts app running always in design mode: Any performance hit? yashgt@gmail.com Microsoft ASP .NET 1 8th Aug 2007 02:02 AM
Switch between Design Mode and "Running" Mode =?Utf-8?B?Y2xhcmE=?= Microsoft Excel Programming 1 19th Mar 2007 11:33 PM
Re: Enter Excel Design Mode and Exit Design Mode Bill Lunney Microsoft Excel Programming 0 4th Aug 2003 07:48 AM
Re: Design Mode - My Constructor keeps running in design! Jeremy Cowles Microsoft Dot NET Framework Forms 3 18th Jul 2003 02:27 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:09 AM.