Is is possible to retrieve the ID value from the Request.QueryString from a aspx file and pass it onto a ascx file in order to successfully update a profile using the retrieved ID?
Often if something is in a UserControl, it is either because the functionality in the control is significant enough to be broken out into it's own reusable container that could be reused on another page. If that control is actually ever going to be reused on another page, it really shouldn't be referencing query string parameters because the control should make no assumptions about what page it is on. What if that control gets included on another page whose query string parameters are named differently? Or maybe on another page that value will come from the database or ViewState or will be automatically determined somehow? So my general rule is that if you are going to make a UserControl, never, never never make any assumption about the page it is being hosted on.
So like most people said, you can still access the Request.QueryString property from inside the UserControl, but that would probably not be the best idea. Creating a property on the control that gets set by the container page is a far better idea.
The best idea in my opinion, and what I almost always do, is create method called LoadData (or something similar) on the control, with parameters for all of those query string values you need. That way you have a single entry point for that data, so it's clear at what point those values are getting set and what they are getting set to. If you go the property route, there is always concern about whether all of the properties got set, and whether they got set in the right point in the page lifecycle (it can get tricky during postbacks)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With