reference to system.web.ui.page

G

Guest

Hi all,

I have a .cs code file in the App_Code directory. Now how do I get a
reference to the System.Web.UI.Page object? I can get references to Request,
Response and Server through HttpContext.Current, but dont know how to get
Page.

TIA!
 
M

Masudur

Hi all,

I have a .cs code file in the App_Code directory. Now how do I get a
reference to the System.Web.UI.Page object? I can get references to Request,
Response and Server through HttpContext.Current, but dont know how to get
Page.

TIA!

Hi,

Why don't you keep a reference of your page in the session...
then use HttpContext.Current.Session to access the page....

Thanks

Masudur
Kaz Software Ltd.
www.kaz.com.bd
 
B

bruce barker

HttpContext.CurrentHandler is the page (must be cast)

-- bruce (sqlwork.com)
 
J

Jason Kester

Why don't you keep a reference of your page in the session...
then use HttpContext.Current.Session to access the page....

Thanks. It's not often that we get to laugh aloud reading about ASP.NET
development, but this suggestion is so boneheaded that it's added mirth
to many a boring day!

So essentially, here's the pageload you're proposing:
protected void Page_Load()
{
Page.Session["Page"] = Page;
}

and in the usercontrol:
{
Page thisPage = (Page)HttpContext.CurrentHandler;
Page reallyThisPageHonest = (Page)thisPage["Page]";
}

So redundant! So Wasteful! So much genious in one place! Thank you
for keeping the rest of us employed for years to come cleaning up after
your work! (Personally, I'd use Bruce's suggestion, simple and
effective as it might be...)


Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/
 
G

Guest

I dont use Session state in my apps.


Jason Kester said:
Why don't you keep a reference of your page in the session...
then use HttpContext.Current.Session to access the page....

Thanks. It's not often that we get to laugh aloud reading about ASP.NET
development, but this suggestion is so boneheaded that it's added mirth
to many a boring day!

So essentially, here's the pageload you're proposing:
protected void Page_Load()
{
Page.Session["Page"] = Page;
}

and in the usercontrol:
{
Page thisPage = (Page)HttpContext.CurrentHandler;
Page reallyThisPageHonest = (Page)thisPage["Page]";
}

So redundant! So Wasteful! So much genious in one place! Thank you
for keeping the rest of us employed for years to come cleaning up after
your work! (Personally, I'd use Bruce's suggestion, simple and
effective as it might be...)


Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/
 
S

Steven Cheng[MSFT]

Hi Param,

As Jason has mentioned, you can use the HttpContext.Current.Handler to get
the current request's Page handler( as long as the current request is
processed by a Page handler rather than other custom handler). e.g.

================
Page page = HttpContext.Current.Handler as Page;

if (page != null)
{
Page.RegisterStartupScript........
}

==============

BTW, is there any particular requirement that you have to reference the
current page in class library wthout passing the page reference? If
possible, I think pass a page reference as parameter(or store it in
constructor) will be prefereed.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Bruce's method worked. Well rather than passing stuff by reference, would be
easier if i can get it right?
 
S

Steven Cheng[MSFT]

If your App_Code component is always used in Page code, you can pass the
Page reference in component's constructor, and this is also what many
ASP.NET built-in component and classes do. If using
HttpContext.Current.handler, you need to check the handler type since it is
not always Page handler.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

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,780
Messages
2,569,611
Members
45,278
Latest member
BuzzDefenderpro

Latest Threads

Top