Hi
How can use QueryString in ASP.NET?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Kunal Naik163 reputationPosted Nov 16, 2011, 10:33 PM EST
Please have a look on below links for Query String in ASP.NET with example,
Link1
Link2
karthik v115 reputationPosted Nov 16, 2011, 11:38 AM EST
http://www.c-sharpcorner.com/uploadfile/dhananjaycoder/simple-explanation-for-very-beginners-of-query-string/
AartiRank #2,383 · 594 reputationPosted Nov 16, 2011, 7:03 PM EST
What are Query Strings
Query strings are data that is appended to the end of a page URL.
They are commonly used to hold data like page numbers or search terms or other data that isn't confidential.
Unlike ViewState and hidden fields, the user can see the values which the query string holds without using special operations like View Source.
Query strings are included in bookmarks and in URLs that you pass in an e-mail.
They are the only way to save a page state when copying and pasting a URL.
The Query String Structure
query strings are appended to the end of a URL.
First a question mark is appended to the URL's end and then every parameter that we want to hold in the query string.
The parameters declare the parameter name followed by = symbol which followed by the data to hold.
Every parameter is separated with the ampersand symbol.
You should always use the HttpUtility.UrlEncode method on the data itself before appending it.
Query String Limitations
You can use query string technique when passing from one page to another but that is all.
If the first page need to pass non secure data to the other page it can build a URL with a query string and then redirect.
You should always keep in mind that a query string isn't secure and therefore always validate the data you received.
There are a few browser limitation when using query strings. For example, there are browsers that impose a length limitation
on the query string.
Another limitation is that query strings are passed only in HTTP GET command.
How To Use Query Strings
When you need to use a query string data you do it in the following way:
string queryStr = Request.QueryString["data"];
I hope it will help you.
Thanks.
Datta KharadRank #2,135 · 668 reputationPosted Nov 16, 2011, 7:26 PM EST
string number1 = Request.QueryString[0];
string number2 = Request.QueryString[1];
// The other way to Read the values
//string number1 = Request.QueryString["Number1"];
//string number2 = Request.QueryString["Number2"];
int result = Convert.ToInt32(number1) + Convert.ToInt32(number2);
Label2.Text = result.ToString();
TulasiRank #2,544 · 549 reputationPosted Nov 16, 2011, 9:25 PM EST
Disadvantage: it is visible to user , no security
passing values from current page to employeeinfo.aspx page
Ex: Response.Redirect("Employeeinfo.aspx?id=1001");
if u want o pass more than one values then use '&' to diffenrentiate
like Response.Redirect("Employeeinfo.aspx?id=1001&dept=10");
accessing Query string in Emploeeinfo.aspx (code behind)
Ex: int id=Convert.ToInt32(Request.QueryString["Number1"]);
Satyapriya NayakRank #47 · 31.5K reputationPosted Nov 16, 2011, 9:50 PM EST
Please refer the below link
http://www.codeproject.com/KB/aspnet/QueryString.aspx
Thanks
Prabhu RajaRank #861 · 2.6K reputationPosted Nov 17, 2011, 2:42 AM EST
Hope these Articles Will Help You.
http://www.c-sharpcorner.com/UploadFile/jalajakshi.venkataramana/StateManagementInWebForms11262005051214AM/StateManagementInWebForms.aspx