VB.net Tutorials with Examples

VB.Net Projects

VB.Net Project 1

adplus-dvertising
Query String In ASP.NET
Previous Home Next

Query string is used to Pass the values or information form one page to another page.The query string is a holdover from the ASP days of web programming. You will see this a lot when you are surfing around the internet. Basically, it is passing information to the next page with the URL .You can use a query string to submit data back to your page or to another page through the URL. Query strings provide a simple but limited way of maintaining some state information.

The advantages of using query strings are

  • No server resources required. The query string is contained in the HTTP request for a specific URL.
  • Broad support. Almost all browsers and client devices support passing values in a query string
  • it is very easy

The disadvantages of using query strings are

  • Security. The information in the query string is directly visible to the user via the browser user interface. The query values are exposed to the Internet via the URL so in some cases security may be an issue.
  • Limited capacity. Most browsers and client devices impose a 255-character limit on URL length

.VB CODE

Protected Sub btnSubmit_Click(ByVal sender As Object, 
ByVal e As System.EventArgs) Handles btnSubmit.Click
Response.Redirect("Default.aspx?Name=" & Convert.ToString(Me.txtName.Text) & 
"&LastName=" & Convert.ToString(Me.txtLastName.Text))
End Sub

Our first code part builds a query string for your application and send contents of your textboxes to second page. Now how to retrieve this values from second page.Put this code to second page page_load

Protected Sub Page_Load(ByVal sender As Object, 
ByVal e As System.EventArgs) Handles Me.Load
        Me.txtBox1.Text = Request.QueryString("Name")
        Me.txtBox2.Text = Request.QueryString("LastName")
End Sub
Previous Home Next