Explain how to pass a querystring from an .asp page to aspx page. - ASP.NET

Explain how to pass a querystring from an .asp page to aspx page.

Consider the following URL:
http://localhost/form.aspx?param1=career&param2=ride

This html addresses use QueryString property to pass values between pages.

From the URL above the information obtained is:

form.aspx: which is the destination page for your browser.
Param1 is the first parameter, the value of which is set to career
Param2 is the first parameter, the value of which is set to ride

The ‘?’ marks the beginning of the QueryString
‘&’ is used as a separator between parameters.
private void formButtonSubmit_Click(object sender, System.EventArgs e)
{
    Response.Redirect("form.aspx?Param1=" +
    this.formTextfieldParam1.Text + "&Param2=" +
    this. formTextfieldParam2.Text);
}

The above code is a submit button event handler and it sends the values of the query string to the second page.

The following code demonstrates how to retrieve these values on the second page:
private void Page_Load(object sender, System.EventArgs e)
{
    this.form2TextField1.Text = Request.QueryString["Param1"];
    this. form2TextField2.Text = Request.QueryString["Param2"];
}


You can also use the following method to retrieve the parameters in the string:
for (int i =0;i < Request.QueryString.Count;i++)
{
    Response.Write(Request.QueryString[i]);
}

How to pass a querystring from an .asp page to aspx page?

From HTML in asp page:
<ahref="abc.aspx?qstring1=test">Test Query String</a>

From server side code:
<%response.redirect "webform1.aspx?id=11"%>
What is a ViewState? - ASP.NET
What is a ViewState? - If a site happens to not maintain a ViewState, then if a user has entered some information in a large form with many input fields and the page is refreshes, then the values filled up in the form are lost...
What is the difference between src and Code-Behind?
What is the difference between src and Code-Behind? - With the ‘src’ attribute, the source code files are deployed and are compiled by the JIT as needed...
What is the difference between URL and URI?
What is the difference between URL and URI? - A URL (Uniform Resource Locator) is the address of some resource on the Web. A resource is nothing but a page of a site...
Post your comment