Surpressing WebControl property setter code at Design Time

K

ktrvnbq02

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
 
B

Brock Allen

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.
 
K

ktrvnbq02

Brock said:
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
 
B

Brock Allen

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top