Re: Global property
From: Greg Burns (greg_burns_at_DONT_SPAM_ME_hotmail.com)
Date: 09/06/04
- Next message: Greg Burns: "Re: Write Panel's innerText"
- Previous message: Aaron: "Re: A good site to learn asp.ent, ado.net and access databases?"
- Maybe in reply to: Mark Goldin: "Global property"
- Next in thread: Greg Burns: "Re: Global property"
- Messages sorted by: [ date ] [ thread ]
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
> > > >
> > > >
> > >
> > >
> >
> >
>
>
- Next message: Greg Burns: "Re: Write Panel's innerText"
- Previous message: Aaron: "Re: A good site to learn asp.ent, ado.net and access databases?"
- Maybe in reply to: Mark Goldin: "Global property"
- Next in thread: Greg Burns: "Re: Global property"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|