Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get parameters on Page_Load

Tags:

asp.net

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

like image 560
user1568613 Avatar asked Dec 03 '22 01:12

user1568613


2 Answers

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#

like image 180
Darren Wainwright Avatar answered Dec 14 '22 11:12

Darren Wainwright


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
like image 39
Hector Fuentes Avatar answered Dec 14 '22 11:12

Hector Fuentes