How to use Query string in asp.net

Querystring:

Query string is used to Pass the values or information form one page to another page.
Syntax
Request.QueryString(variable)[(index)|.Count]
Parameters
variable :-
Specifies the name of the variable in the http query string to retrieve.
index :-
An optional parameter that enables you to retrieve one of multiple values for variable. It can be any integer value in the range 1 to Request.QueryString(variable).Count.

For exapmle:-
In page 1:
Drag and drop the one textbox and button control
In page 2:
Drag and drop the one textbox control from tool box and place it on form.
In page one:-


Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'bind the textbox values to querystring
Response.Redirect("Default2.aspx?Textboxvalue=" & TextBox1.Text)

End Sub
End Class

In page two:-

Partial Class Default2
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Get the values from Query string
TextBox1.Text = Request.QueryString("Textboxvalue")
End Sub
End Class


Comments

Author: Manindra Kumar Upadhyay02 Apr 2010 Member Level: Gold   Points : 1

try this link:
http://manindra.net/post/2010/03/29/What-is-Query-String-and-What-are-benefits-and-limitations-of-using-Query-Strings.aspx

Author: shashi shekhar02 Apr 2010 Member Level: Bronze   Points : 2

This is the Way to Send data one Page from other using QueryString

Page1

protected void Button_Click(object sender, EventArgs e)
{
int ID = 10;
string name = "SHASHI";
Response.Redirect("Default1.aspx?id="+ID+"&name="+name);
}
Page2

protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString[0] != null && Request.QueryString[1] != null)
{
/* string id = Request.QueryString[0].ToString();
string name = Request.QueryString[1].ToString();
*/
string id = Request.QueryString["id"].ToString();
string name = Request.QueryString["name"].ToString();


Response.Write(id + "
" + name);
}
}

Author: shashi shekhar02 Apr 2010 Member Level: Bronze   Points : 2


a href="Default3.aspx?id=10&name=shashi" Click Me /a


protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString[0] != null && Request.QueryString[1] != null)
{
/* string id = Request.QueryString[0].ToString();
string name = Request.QueryString[1].ToString();
*/
string id = Request.QueryString["id"].ToString();
string name = Request.QueryString["name"].ToString();


Response.Write(id + "
" + name);
}
}

Author: chidambaram09 Feb 2012 Member Level: Gold   Points : 0

thanks..shashi

Guest Author: Amdi22 Mar 2012

Nice Articles .....!
For Dot Net Jobs and IT Jobs Visit www.amditechnology.com

Guest Author: rajitha02 Apr 2012

thank u for your answer

Guest Author: deepu16 Aug 2014

we take one textbox control and one button on page textbox for entering message by user and we want to show this entered message on other page.
http://asp-net-by-parijat.blogspot.in/2014/08/how-to-use-query-string-in-aspnet.html



  • 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: