Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Surpressing WebControl property setter code at Design Time

Reply
Thread Tools

Surpressing WebControl property setter code at Design Time

 
 
ktrvnbq02@sneakemail.com
Guest
Posts: n/a
 
      03-14-2005
Hi,

I have a WebControl that exposes various properties to the designer in
Visual Studio 2003.

One of these property setters may throw an exception depending on the
contents of some cached data held in a static class elsewhere in the
project (i.e. the property contents is looked up in the cache, which
may cause an exception)

The property setter code works exactly as intended at runtime. However,
it is also running at design-time which I don't want. The reason I
don't want it to run is that it will cause the cache initialization
code to run, which I don't want to happen at that point.

Just to be clear, the property is structured as follows:

public string DbField
{
get
{
return mDbField;
}

set
{
ValidateDbField(value); // <-- I do not want this to run when in
the designer
mDbField = value;
}
}


So is it possible to have the property available in the designer, but
for the designer to not invoke the actual setter code?

Let me know if this is at all unclear.



Regards,

Matt

 
Reply With Quote
 
 
 
 
Brock Allen
Guest
Posts: n/a
 
      03-14-2005
Since ASP.NET doesn't publicly expose the DesignMode property that it uses
internally to detect if it's being used in VS.NET, I tend to check HttpContext.Current
== null to know if I'm not really executing in ASP.NET, and therefore the
designer (or somewhere else, since that's a possibility). But in general,
this does the trick.

-Brock
http://staff.develop.com/ballen

> Hi,
>
> I have a WebControl that exposes various properties to the designer in
> Visual Studio 2003.
>
> One of these property setters may throw an exception depending on the
> contents of some cached data held in a static class elsewhere in the
> project (i.e. the property contents is looked up in the cache, which
> may cause an exception)
>
> The property setter code works exactly as intended at runtime.
> However, it is also running at design-time which I don't want. The
> reason I don't want it to run is that it will cause the cache
> initialization code to run, which I don't want to happen at that
> point.
>
> Just to be clear, the property is structured as follows:
>
> public string DbField
> {
> get
> {
> return mDbField;
> }
> set
> {
> ValidateDbField(value); // <-- I do not want this to run when in
> the designer
> mDbField = value;
> }
> }
> So is it possible to have the property available in the designer, but
> for the designer to not invoke the actual setter code?
>
> Let me know if this is at all unclear.
>
> Regards,
>
> Matt
>




 
Reply With Quote
 
 
 
 
ktrvnbq02@sneakemail.com
Guest
Posts: n/a
 
      03-16-2005
Brock Allen wrote:

> Since ASP.NET doesn't publicly expose the DesignMode property that it

uses
> internally to detect if it's being used in VS.NET, I tend to check

HttpContext.Current
> == null to know if I'm not really executing in ASP.NET, and therefore

the
> designer (or somewhere else, since that's a possibility). But in

general,
> this does the trick.


Thanks -- that's solved it nicely. I should have considered a solution
like that earlier, as we do a HttpContext check in our page base class
constructor for similar reasons.

It's a shame that Microsoft haven't provided developers an attribute to
surpress evaluation of the property at design time, but I guess there
may be certain situations where that could get quite complicated to get
working.


Thanks again,

Matt

 
Reply With Quote
 
Brock Allen
Guest
Posts: n/a
 
      03-16-2005
> It's a shame that Microsoft haven't provided developers an attribute
> to surpress evaluation of the property at design time, but I guess
> there may be certain situations where that could get quite complicated
> to get working.


Well, there is an internal DesignMode property from the Control base class.
Woah! I just noticed it's also protected -- you should be able to use this.
I don't know why I didn't notice it sooner. Maybe this is new in 2.0?

-Brock
DevelopMentor
http://staff.develop.com/ballen




 
Reply With Quote
 
 
 
Reply

Thread Tools

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
@x.setter property implementation Floris Bruynooghe Python 9 04-11-2008 12:07 PM
Property Descriptor - Public Getter, Private Setter gamehack Python 2 07-18-2007 08:51 PM
WebControl with Collection Property in Design Time Mirek Endys ASP .Net Web Controls 6 11-11-2005 11:14 AM
WebControl with non-WebControl property Peter Morris [Air Software Ltd] ASP .Net Web Controls 1 12-07-2004 12:25 PM
Composite WebControl -- Child Control Property Persistance at Design-time Bob Brunton ASP .Net Building Controls 9 02-16-2004 11:11 AM



Advertisments