Reputation: 209
I have a page which contains a dynamic number of custom WebControls. What I want to do is get the containing page's query string via "Request.QueryString".
If I understand the problem correctly I need the containing page's HttpRequest object?
Is there a way to do this?
I probably should point out that I don't want to pass the QueryString from the containing page to the WebControl. I want to access the QueryString directly from the WebControl.
Upvotes: 4
Views: 7785
Reputation: 35156
Consider the following link:
HttpContext.Current.Request.QueryString
Upvotes: 7
Reputation: 96606
You should be able to access the query string from a custom web user control (ascx) in the same way as you do from the page, i.e:
Request.QueryString...
From a custom control, you can either access it via:
Page.Request.QueryString
//or
HttpContext.Current.Request.QueryString
BTW: the last option (System.Web.HttpContext.Current...
) also works from any non-web-control classes (e.g. business logic).
Upvotes: 3
Reputation: 8166
No need to to anything in particular, Request object is directly available also to webcontrols:
this.Request.QueryString
Upvotes: 0
Reputation: 9113
you can access the httpContext from anywhere using
HttpContext.Current
From there you can find the Request and the querystring
Upvotes: 0