ARTICLE

How to work with QueryString in ASP.NET using VB.NET

Posted by Dea Saddler Articles | ASP.NET using VB.NET May 04, 2011
In this article you learned about QueryString.
Download Files:
 
Reader Level:


Introduction

QueryString is used to pass the value of information from one page to another page. The syntax for the QueryString is (Request.QueryString(variable)[(Index)|.Count]Parameters). The variable in the Syntax specifies the name of variable in the HTTP QueryString to retrieve. The Index in the Syntax is an optional parameter that Enables you to retrieve one of multiple values for a variable. It can be any integer value in the range 1 to Request.QueryString(variable).count.
The QueryString Collection retrieves the values of the Variables in the HTTP query string. The HTTP query string is specified by the values following the question mark(?).
 

Getting Started

  • Simply create a new ASP.NET web application. 
  • Drag two Label on web page. The page will look like below.

    qstring1.gif
     
  • You can also add the controls by below code.

    <%@ Page Title="Home Page" Language="vb"  AutoEventWireup="false"
        CodeBehind="Default.aspx.vb" Inherits="QueryString._Default" %>
    <html>
    <
    head>
    <
    title>QueryString Sample Page</title>
    </
    head>
    <
    body >
    <
    form id="Form1" runat="server">
    <
    font face="Vardana">
    <
    asp:Label
        id="lblMessage1"
        runat="Server"
        Font-Bold="True"
    />
    <
    br></br>
    <
    asp:Label
        id="lblMessage2"
        runat="Server"
        Font-Bold="True"
    />
    </
    font>
    </
    form>
    </
    body>
    </
    html>
     
  • Then add the below code in code behind file of the web page.

       
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Len(Request.QueryString("StoreID")) = 0 _
               
    Or Len(Request.QueryString("ProductID")) = 0 Then
                lblMessage1.Text = "One or both of the fields " _
                    &
    "StoreID or ProductID were not found in the " _
                    &
    "QueryString collection!"
            Else
                lblMessage1.Text = "Store ID: " _
                    & Request.QueryString(
    "StoreID")
                lblMessage2.Text =
    "Product ID: " _
                    & Request.QueryString(
    "ProductID")
           
    End If
        End Sub
     
  • Now run your application
     

Output:-

qstring2.gif

Summary

In this article you learned that how to work with QueryString.

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Nevron Diagram
Become a Sponsor