Practical of Query String


In this Article we discuss about the practical implementation of the Query String. I f you are new in this article , So learn some important concept of Query String under this url : http://www.dotnetspider.com/resources/46056-State-Management.aspx . Once you understand the theoretical concept, in this Article we discuss the practical implementation for better understanding.

In this Article we use GUI and code behind in Steps, So please follow these Steps according to the Numbers.

In case of Query String data or Information is concatenate in the URL.

Step 1. Select webform from the VS. Place a textbox and a button from the toolbox.Use the Below Code.

QuerySting1

protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Default2.aspx?ab=" + TextBox1.Text);
}


Note : In the above code Default2.aspx represent the page where we want to send the data.
"?" denote that we are use the Query String
ab is the Query String Variable Name and this ab is concatenate in the URL.

Step 2. Select another webform in the same Solution Explorer. Place a Label.

protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Request.QueryString["ab"].ToString();
}

Note : You have notice that on page load Event we request the Query String variable with same name that is Concatenation in the URL. If we use any other QS variable name instead of ab it shows error.

Example :
Run the Program and put any text in the Textbox and the press on the button.And also check the URL. And check the URL there is Default.aspx is written in the URL.

QueryString2

Now when we press on the button then it redirect to the new page that we can define in the code behind.And now check the URL some amount of information is concatenate in the URL with Query String variable ab. Check the URL Default2.aspx?ab=Amit now information is concatenate in the URL.

QueryString3

Now If you understand the concept then solve the below Question ?
Q. How to pass the Multiple values in the Query String?
Q. How to Access the Multiple Values in the Query String?


Download Attachment of Query String Practicle


Attachments

  • Attachment of Query String Practicle (46071-4-Attachment-of-Query-String-Practicle.rar)
  • Comments

    Author: sridhar thota02 May 2015 Member Level: Gold   Points : 4

    Q. How to pass the Multiple values in the Query
    String?
    A)QueryStrings are separated by & symbol.
    If we want more than one value to be passed in QueryString then we should use "&" between two QueryStrings.

    With in the Button1_Click event of Default.aspx, am sending three values Name, Password and Id for second webpage Default2.aspx with in the url.


    protected void Button1_Click(object sender,
    EventArgs e)
    {
    Response.Redirect("~/Default2.aspx?Name=" +
    TextBox1.Text + "&Password=" + TextBox2.Text + "&Id=" + TextBox3.Text );
    }


    Regards

    Sridhar.
    DNS Member.
    "Hope for the best.. Prepare for the worst.."

    Author: sridhar thota02 May 2015 Member Level: Gold   Points : 5

    Q. How to Access the Multiple Values in the
    Query String?
    A)To read a QueryString value we use Request.QueryString.

    Place 3 labels on webpage Default2.aspx.
    With in the page load logic displaying the QueryStrings values in labels.


    protected void Page_Load(object sender,
    EventArgs e)
    {
    Label1.Text = Request.QueryString["Name"];
    Label2.Text = Request.QueryString["Password"];
    Label3.Text = Request.QueryString["Id"];
    }

    We can use index to read QueryString as well.


    protected void Page_Load(object sender,
    EventArgs e)
    {
    Label1.Text= Request.QueryString[0];
    Label2.Text= Request.QueryString[1];
    Label3.Text= Request.QueryString[2];
    }


    Regards

    Sridhar.
    DNS Member.
    "Hope for the best.. Prepare for the worst.."



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: