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.
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.
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.
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
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.
Regards
Sridhar.
DNS Member.
"Hope for the best.. Prepare for the worst.."