Accessing page variable from control

G

Gerald

Hi,

I have got a page called page1.aspx and the code-behind file.

In that page1.aspx. I declare a web control ctrl1.ascx and the code-behind
for that web control.

Page and web control are both working ok.

Now I declare a public string variable called "sMessage" in the
"page1.aspx.cs" codebehind file.

How can I access it from the control codebehind file (ctrl1.ascx.cs) ?

So in the control codebehind file, I want to check that page value.

But I did not manage to get it. What would be the syntax to access it?

Thanks a lot

Gerald
 
A

Anatoly

You cast Page property of control to your page class
if page1.aspx is page1 class then write:

string theResult = ((page1)Page).sMessage;

HTH
 
G

Gerald

Thanks. It does work.
But is there a way to do it generic?
I mean something like Parent.Page ...
Because I have to call the same routine from different codebehind and
different pages.
So I would be obliged to rewrite the same function in every code behind
file.
A generic function would allow me to inherit from a custom base control.

Thanks

Gerald
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top