I am trying to send url parameters to an .aspx page. Now I need to get thoose parameters on Page_Load() function.
I am using this code to call the new page. How do I need to add the parameters.
window.location = 'AttendanceExcelReport.aspx';
Then what do I need to do in order to get those parameters on the Page_Load function.
Thanks
You would use Querystrings.
I.E your URL should be formatted as follows:
[URL][?][Key=value]
If you are adding multiple parameters then separate with [&]
then your next [key=value]
So:
Here is your URL with 2 parameters, ID and Name:
AttendanceExcelReport.aspx?id=1&name=Report
You can access these by just calling
Request("id")
in VB and Request["id"]
in c#
Request("name")
in VB and Request["name"]
in c#
Let's assume that you want to process an undeterminated number of parameters passed to your page, you can get the QueryString property of the Request object that holds all the query string parameters, and then get these parameters with a couple of for-each. as example:
Dim parameters As System.Collections.Specialized.NameValueCollection
parameters = Request.QueryString
Dim key As String
Dim values() As String
System.Diagnostics.Debug.Print("Number of parameters: " & parameters.Count)
For Each key In parameters.Keys
values = parameters.GetValues(key)
For Each value As String In values
System.Diagnostics.Debug.Print(key & " - " & value)
Next
Next
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