Surpressing WebControl property setter code at Design Time

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

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

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

  3. Guest

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

    > 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
     
    Brock Allen, Mar 16, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gamehack
    Replies:
    2
    Views:
    501
    James Stroud
    Jul 18, 2007
  2. Floris Bruynooghe

    @x.setter property implementation

    Floris Bruynooghe, Apr 6, 2008, in forum: Python
    Replies:
    9
    Views:
    453
    Floris Bruynooghe
    Apr 11, 2008
  3. Bob Brunton
    Replies:
    9
    Views:
    214
    Alessandro Zifiglio
    Feb 16, 2004
  4. Peter Morris [Air Software Ltd]

    WebControl with non-WebControl property

    Peter Morris [Air Software Ltd], Dec 7, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    133
    Peter Morris [Air Software Ltd]
    Dec 7, 2004
  5. Mirek Endys

    WebControl with Collection Property in Design Time

    Mirek Endys, Nov 2, 2005, in forum: ASP .Net Web Controls
    Replies:
    6
    Views:
    216
    Steven Cheng[MSFT]
    Nov 11, 2005
Loading...

Share This Page