Page.Request in class file

  • Thread starter Thread starter Colin \(615498\)
  • Start date Start date
C

Colin \(615498\)

Why is the request and response properties not available from within a class
file? Do I need to refer in same way to objects or classes from the calling
page?

Thanks,
Colin.
 
They are properties of Page class. You need to refer to an instance of Page
class.

For example:

public class aa
{
private System.Web.UI.Page callingPage;

public aa (System.Web.UI.Page callingPage)
{
this.callingPage = callingPage;
}

public string ff ()
{
return callingPage.Request.Params["par1"].ToString()
}
}


Eliyahu
 
Eliyahu said:
They are properties of Page class. You need to refer to an instance
of Page class.

For example:

public class aa
{
private System.Web.UI.Page callingPage;

public aa (System.Web.UI.Page callingPage)
{
this.callingPage = callingPage;
}

public string ff ()
{
return callingPage.Request.Params["par1"].ToString()
}
}


Eliyahu

Or:
You can use System.Web.HttpContext.Current.Request
(and Session, Cache, Response, ..)

But: this will only work if there is really a httpcontext (=called as result of
an http request)

Hans Kesting
 
Hello Colin (615498),

You can use this:

HttpContext.Current.Request or HttpContext.Current.Response

If you need other methods from the Page class, try this:

Page page = (Page)HttpContext.Current.Handler;

HTH!
 
Back
Top