Let's say we have a value coming in through the URL of a page. Example: www.test.com/page.aspx?&Key=Val. Val is retrievable through Request.Querystring("Key").
Is there an accepted best practice for assigning a QueryString Value to a parameter of a SqlDataSource defined on an ASPX page?
Options that I know of:
- Do not include parameters in the ASPX file. Add them directly through the codebehind -- and assign Param.DefaultValue upon adding.
- Set Param.DefaultValue in the page load (Codeblock 2)
Both of these use DefaultValue, a property that clearly was not intended to be used in this manner. Do the ASP.NET overlords have a recommended method in mind for achieving this common task?
Codeblock 1
<SelectParameters>
<asp:Parameter Name="StoreID" Type="String" DefaultValue="-1" />
</SelectParameters>
Codeblock 2:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SD1.SelectParameters("StoreID").DefaultValue = Request.QueryString("StoreID")
End Sub