Get QueryString from inside WebControl

I have a page containing a dynamic number of custom WebControls. What I want to do is get the query string of the containing page through "Request.QueryString".

If I understand the problem correctly, do I need a containing HttpRequest page object?

Is there any way to do this?

I should probably point out that I don't want to pass a QueryString from the containing page to WebControl. I want to access QueryString directly from WebControl.

+4
source share
4 answers

Consider the following link:

HttpContext.Current.Request.QueryString

+7
source

You should be able to access the query string from a user-defined user control (ascx) in the same way as from a page, i.e.

Request.QueryString... 

From a user control, you can either access it through:

 Page.Request.QueryString //or HttpContext.Current.Request.QueryString 

BTW: the last option ( System.Web.HttpContext.Current... ) also works from any classes that are not related to web management (for example, business logic).

+3
source

you can access httpContext from anywhere using

 HttpContext.Current 

From there you can find Request and querystring

0
source

There is no need for anything in particular, the request object is also directly accessible for webcontrols:

 this.Request.QueryString 
0
source

All Articles