Accessing page variable from control

  • Thread starter Thread starter Gerald
  • Start date Start date
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
 
You cast Page property of control to your page class
if page1.aspx is page1 class then write:

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

HTH
 
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
 
Back
Top