Re: web controls are NOT good use of encapsulation

From: Scott (noemail_at_this-is-extra-hotmail.com)
Date: 04/14/04


Date: Wed, 14 Apr 2004 14:38:20 -0400


 It's not as inexpensive as a method call; it depends on how you are using it -- in the end it's up to you. The example I sent you
does return a value, so you should be able to run some tests and see if you are going to have a problem.

 As far as a design pattern for Parent/Child relationships in ASP.NET; I guess my preference is for a control that requires a
particular value from the outside to enforce that via the compiler -- hence my preference for subclassing -- or at runtime using
exceptions (i.e. "I'm a control that needs something and you didn't provide it..."). What you suggest -- broadcasting -- sounds like
something I might have done in my old Perl/scripting days; arguably, I think the C# approach makes for better applications and
certainly makes it easier to build larger applications.

Good luck.

"Jason Shohet" <__ash477@yahoo.com> wrote in message news:Oqm54ekIEHA.4020@TK2MSFTNGP10.phx.gbl...
> You hinted that Reflection is hard on resources, is that true?
>
> > you might create your own Page subclass, then in your control you could do
> the following:
> > ....
> > MyPage page = this.Page as MyPage;
> > if (page != null)
> > OrgValue = page.GetOrg();
> > else
> > OrgValue = // some default
>
> Ok, above: If this.Page.GetOrg() is used when the control sits on a
> regular webpage, it won't work because that func. hasn't been compiled as
> part of the class (?) -- so .NET doesn't see it unfortunately at
> compiletime.
> But as you say, if I inherit a new page subclass, and add that method, and
> compile that page, this.Page.GetOrg() will be a func. available to be seen
> from the control, thats a good idea. But it sorta limits reusability
> because I'll have to remember every time I use this control that it can only
> be placed on a page subclass which has this method on it. A regular webpage
> with this method on it, Page.GetOrg() won't be able to see it w/o
> reflection, and with reflection it can't return a value (seemingly). Still
> thats a good solution.
>
> > Or, if the Org value is something that is global to the application,
> consider using the Global.asax; then the Control could do:
> > OrgValue = Global.GetOrg();
>
> I'm not sure how global.asax works in the above, to tell you the truth. I
> always thought the global is so you could do things on certain global events
> like Application.Start. IE, In Application Start, I would get the
> connection string from someplace (like web.config), and put it into the
> Application object. Then later on I can get it back from the application
> object. But can the global.asax store a value, without the applicaiton
> object / session to help it? I'll read up on this a bit ;)
>
>
> > case you describe is kind of opposite to the way I think of the
> relationship between Pages/Controls -- the Page class (whether a
> > subclass or not) should know what the contract for the child controls it's
> using are, and set them up accordingly.... but I'm not a
> > fanatic about it :)
>
> Ok, but the more the parent has to know about items on the control the less
> "plug-and-play" it is. If I have the parent setting a hidden field,
> hf_orgid, well I've gotta remember now to do that everytime I use this darn
> control. If the hidden field isn't populated, the control won't work. It
> seems a better tactic is for the control to attempt to manage as much as it
> can about how it functions. The control knows it needs an organization # to
> work. So let it broadcast a call, "Hey, GetOrg() ! Whomever is my
> parent and hears me, give me that org #". If I forget about this control
> and pick it up in 2 years and plug it in somewhere, it will blow up
> immediately on GetOrg. I'll take a look & see that its looking for a func.
> on its parent that returns an org #. Thats easy to work with.
> But if I pick up the control after 2 years & use it somewhere, and it
> doesn't work because some hidden field or value isn't set correctly, I'll
> have forgotten what I need to do. I'll think, "Maybe the control has a bug
> etc". I'll have to trace it, debug it, only to find out that some hidden
> field has to be set somehow, at some point in time, from outside the
> control. Of course thats what commenting code is for, but still it seems
> neater to see that there's a function call built-in to the control which is
> expecting back a value from its parent.
>
> Sorry 2 babble & ty for the advice, Jason Shohet
>
>



Relevant Pages

  • Re: Catching Spin Control Events From CEdit
    ... I'm just allowing several formats of numbers and so I needed code to ... I didn't need to subclass the UDC for my purposes, ... > subclass the parent in order to intercept the ... I have several instances of this control on several dialog boxes, ...
    (microsoft.public.vc.mfc)
  • Re: MFC and c++ problems
    ... You say that a control must make no assumptions about its parent. ... messages to its parent will compile and run ... ... One could write an interface class that supported the methodneeded by ...
    (microsoft.public.vc.mfc)
  • Re: Is it possible to separate the event-handling part from the control?
    ... The font would be set by SetFont, but that's a different issue than having the parent ... desired background color by calling a method of the control subclass, ... color in the subclass, where it belongs. ...
    (microsoft.public.vc.mfc)
  • Re: Controls - Page_init order
    ... the control after the Page_Load. ... Parent that says "Inside the Parent Page_Load", ... e as EventArgs) Dim sTest as String trace.warn("Inside the ... execute first before anything else since it is initialization code. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Is it possible to separate the event-handling part from the control?
    ... color in the subclass, where it belongs. ... that the parent should be in control is not only not sound, ... Note that the parent has to have knowledge of EVERY CONTROL in it, ... The proper way is for the parent to set a font property at runtime. ...
    (microsoft.public.vc.mfc)