How to refer Page level variable from a control?

O

Oleg Slyuasrchuk

Hi,

I have a composite control inherited from System.Web.UI.Control.

Inside of this control I need to refer to a Page level variable decalared
as
public string channelStructure.

In a debugger I see value of this variable as :

((CmsFormEditor.EditForm)(((ASP.EditForm_aspx)(((System.Web.UI.Page)((this.P
age))))))).channelStructure

As one can guess, ASP.EditForm_aspx is class created by ASP.NET runtime from
the page EditForm.aspx
where I place the control and this.Page is starting point to find the
variable.

Since I'm trying to write a generik control, I don't want to refer to
specific page name.
So, I need more generic way to refer the Page level variable.

Any help is appreciated.

Oleg
 
A

Alessandro Zifiglio

Why is your control trying to reference a variable on the page. Its supposed
to be the other way round.
 
O

Oleg Slyusarchuk

Thanks for the answer.

I DO need to access a variable that holds a property that will be common
for all of my controls on the page.
For simplicity, it can be page's virtual path (maybe modified in some
way). This value will be set up dynamically (calculated) at page level.

Oleg
 
K

Kelly Leahy

Since I'm trying to write a generik control, I don't
want to refer to
specific page name.
So, I need more generic way to refer the Page level variable.

I agree with the other posting. It should be the other
way around, no control should ever be able to access a
page level variable on the page that contains it.
Generally, when you are writing a custom control that
needs information from the page, it should provide an
event with an out or ref variable (ByRef in VB) so that
the page can catch the event and provide the necessary
information. However, that's not possible, as far as I
can tell in the .NET event framework, so instead you need
a custom EventArgs object. For instance, see the
ImageClickEventArgs in the ImageButton control. You
would define your own such public type, and make it the
second argument for the delegate declaration for the
event handler type (see ImageClickEventHandler). In your
custom EventArgs object, you would expose a property that
allows the containing page to provide the information you
need (be setting properties on the custom EventArgs
object).

I'm sorry if this sounds complicated, but it really is
the best way to get information from the page.
Alternatively, you can require the page developer to
provide the information as a property of your control and
keep it synchronized whenever it changes, but that would
be messy.

Feel free to give more details about the nature of the
variable you need to access and perhaps we can provide
more assistance...

Kelly Leahy

For instance, if your custom control needs information
for a property called X, you would expose an event called
GetX with a signature such as GetX(ref X as object)
 
K

Kelly Leahy

For instance, if your custom control needs information
for a property called X, you would expose an event called
GetX with a signature such as GetX(ref X as object)
.

Sorry, that last stuff somehow made it's way in, but it
shouldn't be there... I thought I deleted it from the
message.

Hope it didn't confuse too much...
 
O

Oleg Slyusarchuk

Thank you, kelly

I posted more detailed message "Communications between controls" in
microsoft.public.dotnet.framework.aspnet.webcontrols

My idea is to make controls self-contained and not force
developers that are going to use my controls to code anything.
I undestand that I make assumptions about existence of another
control(s) on the page, but this is situation easily catchable.

Oleg
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top