ASP.NET QueryString using VB.NET

In this article you learned about QueryString.
  • 6199
 

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.

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.