RE: VS Designer inadvertently changes control declarations in code-beh

Discussion in 'ASP .Net' started by =?Utf-8?B?WXVyaSBWYW56aW5l?=, Jul 22, 2004.

  1. In addition I would like to mention that the System.UI.Web.UserControl class has FindControl(string ControlID) Method which returns a Child Control as publicly accessible, except you have to cast it to use it and it is ugly. Compare:

    this.pnlTypes.Visible = false;

    vs.

    ((Panel)FindControl("pnlTypes")).Visible = false;

    Sometimes I prefer the 2nd method, other times the 1st, but the bottom line is I should have freedom of choice.




    "Yuri Vanzine" wrote:

    > I think what I am about to describe is a VS.NET 2003 bug. In my project I am deliberately breaking the debatable Demeter principle http://www.c2.com/cgi/wiki?LawOfDemeter in effort to provide a degree of flexibility in control access from page level.
    >
    > My Project class hierarchy includes several user controls (.ascx), inherited from a certain BaseUserControl, which are reused throughout different pages(aspx).
    >
    > I need individual web control access on an ascx from aspx pages, therefore I declare them public in ascx.cs like this:
    >
    > public Panel pnlType;
    > public Panel pnlStatuses;
    > public Panel pnlMeters;
    > public Panel pnlInstrumentDates;
    > ...
    >
    > I can later on access these panels from aspx.cs code-behinds like this:
    >
    > this.pnlTypes.Visible = false;
    >
    > Therefore I need them public through a conscious choice of mine. However, I am facing the following problem:
    >
    > When I open my ascx control in VS Designer, it changes the control declarations from public to protected in ascx.cs code-behind, thus forcing me into Law of Demeter.
    >
    > I can submit to LoD and the stubborn will of VS.NET Designer and instead set up a public accessor for all my protected members, but I still would like to find a way to make public declarations work w/o VS Designer breaking them.
    >
    > I end up undoing the changes that VS Designer forces upon me every time it changes my control code-behind, but my ultimate question is why should VS.NET IDE change my code at all?
    >
    > Thank you,
    >
    > Yuri Vanzine
    =?Utf-8?B?WXVyaSBWYW56aW5l?=, Jul 22, 2004
    #1
    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. =?Utf-8?B?SmViQnVzaGVsbA==?=

    How to Make Code-Behind Reflect Changes To Designer?

    =?Utf-8?B?SmViQnVzaGVsbA==?=, Dec 14, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    395
  2. =?Utf-8?B?cmVuZ2VlazMz?=

    DropDownList.SelectedValue resets inadvertently

    =?Utf-8?B?cmVuZ2VlazMz?=, Dec 21, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    2,549
    =?Utf-8?B?cmVuZ2VlazMz?=
    Dec 22, 2005
  3. =?Utf-8?B?U0RSb3k=?=
    Replies:
    0
    Views:
    5,387
    =?Utf-8?B?U0RSb3k=?=
    Apr 26, 2006
  4. Steve B.
    Replies:
    4
    Views:
    953
    Cheryl D Wise
    Jun 1, 2007
  5. Alexander Higgins
    Replies:
    3
    Views:
    1,067
    Teemu Keiski
    Jul 30, 2007
Loading...

Share This Page