Surpressing WebControl property setter code at Design Time

Discussion in 'ASP .Net Web Controls' started by ktrvnbq02, Mar 14, 2005.

  1. ktrvnbq02

    ktrvnbq02 Guest

    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
     
    ktrvnbq02, Mar 14, 2005
    #1
    1. Advertisements

  2. ktrvnbq02

    Brock Allen Guest

    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 Allen, Mar 14, 2005
    #2
    1. Advertisements

  3. ktrvnbq02

    ktrvnbq02 Guest

    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
     
    ktrvnbq02, Mar 16, 2005
    #3
  4. ktrvnbq02

    Brock Allen Guest

    It's a shame that Microsoft haven't provided developers an attribute
    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 Allen, Mar 16, 2005
    #4
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.