C# – Pass Query String to User Control from Parent Page

asp.netcuser-controls

i have create a user control search.ascx with query string values and i m accessing this page from Parent page(Rcomm.aspx) and now this Page is open from another page(view.apsx) on button click using hyperlink navigateurl. my question is that how can i pass my user control query string from view.aspx

Best Answer

A user control has access to the page's URL the same as any normal ASP.NET page does; thus, in order to retrieve the QueryString from the user control, the normal syntax will work:

Request.QueryString('key')

However, I consider this poor style, because I think of user controls as a modular item you can embed in ANY page: thus tying it directly to a particular querystring value seems to go against that. However you may have valid reasons for this.

I'm not sure I understand the second part of your question:

how i make hyperlink navigate URL with query string for open my Rcomm.aspx

Could you please clarify?

ADDITIONAL: OK it seems to me like you have a link in your user control, and want to use a querystring value from the user control's parent page (Rcomm.aspx) to use in the link to a third page. Correct me if I am wrong.

In this case, you would read the querystring from the user control, then append to another URL using NavigateURL:

URL: Rcomm.aspx?field=value

(in code behind:)

Dim qs as string

qs = Request.QueryString('field')

MyHyperlink.NavigateURL = "newpage.aspx?field2=" & qs

Or something similar. Yes?