开发者

Get QueryString from inside a WebControl

开发者 https://www.devze.com 2023-04-09 04:04 出处:网络
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\".

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 containi开发者_开发百科ng page to the WebControl. I want to access the QueryString directly from the WebControl.


Consider the following link:

HttpContext.Current.Request.QueryString


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).


you can access the httpContext from anywhere using

HttpContext.Current

From there you can find the Request and the querystring


No need to to anything in particular, Request object is directly available also to webcontrols:

this.Request.QueryString
0

精彩评论

暂无评论...
验证码 换一张
取 消