Popular Posts

Jan 4, 2011

Redirect Pages(QueryString)

ASP.NET provides a few ways to move to different pages. In this post i try to show you how
you redirect from first page to second page.and how you get the value.

Step1:Open your project and take textbox and a button.
Step2: Type the code behind the button
protected void Button1_Click(object sender, EventArgs e)
        Response.Redirect("SecondPage.aspx?Name=" + TextBox1.Text);

Step3: Create a new aspweb page and name it SecondPage.aspx
Step4:Write down the code inside the pageload method
String sString;
        sString = Request.QueryString["Name"];
        Response.Write("Your name is " +sString);

Step5:Set FirstPageUI.aspx as your first page
Step6: Run the project. Give some value to the text field. Click on the button. You will see the result.

Click on the button you will see the result...

There are some advantages and disadvantages of using querystring.
Advantages of this approach
  1. It is very easy.
Disadvantages of this approach
  1.QueryString can not be used to send & and space characters.

  2.QueryString have a max length, If you have to send a lot information this approach does not work.
  3.QueryString is visible in your address part of your browser so you should not use it with sensitive information.

No comments:

Post a Comment