Re: Global property

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Greg Burns (greg_burns_at_DONT_SPAM_ME_hotmail.com)
Date: 09/06/04


Date: Sun, 5 Sep 2004 21:41:25 -0400

Ah, but I would love to see how to do that (the interface design) if you get
a chance. I have an app that utilizes a few user controls across a couple
of webforms. They all need to share the same state. My current method is
extremely ugly. I've made all the user controls have a public property (say
MySettings). In the page load I initialize all the usercontrols MySettings
properties to match the Page's MySettings. Every time there is a change, I
resync all the usercontrols (by raising custom events registered in the
hosting Page). It is very ugly as you can imagine.

I probably should have just shoved MySettings into a Session variable, but I
was trying to keep everything in ViewState instead. (Not sure I am made the
right decision here)

It is very interesting to me to be able to read a common property from the
hosting page directly. My problem is, like I mentioned, my usercontrols are
spread across mutliple webforms and doing a Select Case on a TypeOf seems
uglier yet.

Greg

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:e4ZX%23w6kEHA.556@tk2msftngp13.phx.gbl...
> Sorry Greg,..just realized you aren't the one who asked the original
> question ... :)
>
> Karl
>
>
> "Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
> news:uD19On6kEHA.3772@TK2MSFTNGP14.phx.gbl...
> > Karl,
> >
> > This is quite interesting. But something doesn't seem right to me. A
> > usercontrol can be placed on any page. Won't this cause problems if you
> try
> > and cast the Page object it is "hosted" in to a specific class?
> >
> > Problems may not be the right word. Shouldn't you do some sort of test
to
> > be sure Page is of the correct type before casting?
> >
> > If TypeOf (Page) Is WebForm1 Then
> > dim pageValue as string = ctype(Page, WebForm1).MyValue
> > End If
> >
> > Greg
> >
> > "Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote
in
> > message news:ewa5%23c6kEHA.3772@TK2MSFTNGP14.phx.gbl...
> > > create a public property
> > >
> > > Say your page is of type WebForm1
> > >
> > > Public Class WebForm1
> > > inherits System.Web.UI.Page
> > >
> > >
> > > private _myvalue as string = "SomeValue"
> > > public readonly property MyValue() as string
> > > get
> > > return _myvalue
> > > end get
> > > end property
> > >
> > > Sub Page Load...
> > > ...
> > > End Sub
> > >
> > > ...
> > > End class
> > >
> > > In your user controls, you can access MyValue via:
> > >
> > > dim pageValue as string = ctype(Page, WebForm1).MyValue
> > >
> > >
> > > Every user control has access to the Page, and by casting it to the
> > specific
> > > type, you have access to it's public property/methods..
> > >
> > > Karl
> > >
> > >
> > > "Mark Goldin" <markgoldin@comcast.net> wrote in message
> > > news:eH%23ERI6kEHA.3612@TK2MSFTNGP12.phx.gbl...
> > > > I have main aspx page with a number of user controls.
> > > > How can I create a global property that will be visible in every
user
> > > > control?
> > > >
> > > > Thanks
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Relevant Pages

  • Web User Control...Im missing something basic
    ... I am trying to add 5 "Web User Controls" for use on one WebForm. ... I have created 5 usercontrols in my project (ASP.Net using VB and ... I know that I need to instantiate an instance of ucPage1, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Abstract Usercontrols
    ... we are working on has user controls that are marked as abstract. ... What is the reason for using abstract usercontrols? ... saying the abstract class does not implement the abstract method. ... protected abstract void Save; ...
    (microsoft.public.dotnet.framework.aspnet.buildingcontrols)
  • User controls, postback and passing of variables
    ... I'm working on a web project which consists of one page with several usercontrols in it. ... the thing i hoped anyone maybe could explain to me is: How does Postback work when there are multiple user controls ... (one user control containing a TreeView, one user control containing a mulitple items such as the DataGrid)? ... I was wondering how Postback behaves in this scenario. ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Problem With Winforms UserControl on VS.net design time
    ... I'm not able to use UserControls using my ... When I tried to drag and place the user controls on WinForm ... it shows an error saying "An exception occurred while trying ... And another strange problem ...
    (microsoft.public.dotnet.framework)
  • Problem With Winforms UserControl on VS.net design time
    ... I'm not able to use UserControls using my ... When I tried to drag and place the user controls on WinForm ... it shows an error saying "An exception occurred while trying ... And another strange problem ...
    (microsoft.public.dotnet.framework.windowsforms.designtime)