Resources » Code Snippets » ASP.NET WebForms

How to use Query string in asp.net


Posted Date: 03-Jul-2009  Last Updated:   Category: ASP.NET WebForms    
Author: Member Level: Gold    Points: 4



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



Did you like this resource? Share it with your friends and show your love!

Responses to "How to use Query string in asp.net"
Author: Manindra Kumar Upadhyay    02 Apr 2010Member 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 shekhar    02 Apr 2010Member 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 shekhar    02 Apr 2010Member 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: chidambaram    09 Feb 2012Member Level: Gold   Points : 0
thanks..shashi


Guest Author: Amdi     22 Mar 2012
Nice Articles .....!
For Dot Net Jobs and IT Jobs Visit www.amditechnology.com



Guest Author: rajitha     02 Apr 2012
thank u for your answer


Guest Author: deepu     16 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



Feedbacks      

Post Comment:




  • 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:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Submit Article     Return to Article Index

    Subscribe to Subscribers
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John

    Online Members

    imen
    Priya jain
    More...
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India