Accessing Request Object in Page Class

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I have my own implementation of the Page class which inherits from System.Web.UI.Page. In the constructor ( or as soon as possible) I want to access the query string and get the Id of the page being requested but it doesn't look like I can access this information in the constructor, I get a "Request is not available in this context " error when I do so. Is the onLoad event my best bet or am I missing something?
 
Hi, Neil,

I think the earliest point is if you override the protected void/sub OnInit,
just before the call to base.OnInit(e)/MyBase.OnInit(e):

override protected void OnInit(EventArgs e)
{
// Here
base.OnInit(e);
}

Hope this helps
Martin
Neil said:
Hi,

I have my own implementation of the Page class which inherits from
System.Web.UI.Page. In the constructor ( or as soon as possible) I want to
access the query string and get the Id of the page being requested but it
doesn't look like I can access this information in the constructor, I get a
"Request is not available in this context " error when I do so. Is the
onLoad event my best bet or am I missing something?
 
What about using:

HttpContext.Current.Request.QueryString("Test")


Neil said:
Hi,

I have my own implementation of the Page class which inherits from
System.Web.UI.Page. In the constructor ( or as soon as possible) I want to
access the query string and get the Id of the page being requested but it
doesn't look like I can access this information in the constructor, I get a
"Request is not available in this context " error when I do so. Is the
onLoad event my best bet or am I missing something?
 
Back
Top