Posted by : Anwar Hossain
Category : State Management in ASP C #

Query String Example in ASP.NET C#

Dear viewer's in this tutorial I will explain how to use query string for passing information one page to another page in ASP.Net C#. Browser URL is common way for passing information.In this example I have used Response.Redirect() Method and for getting the query string Request.QueryString() method has been used.

Query String Example in ASP.NET C#

HTML (User Login Page )

<html>

<head id="Head1" runat="server">

    <title>  Welcome to Query String   Example</title>

   

</head>

 

<body>

    <form id="form1" runat="server">

    <div>

        <h2>

            Welcome to Query String   Example

        </h2>

        <fieldset style="width: 40%">

            <legend>User Login</legend>

            <table width="100%" bgcolor="#80AA00" cellpadding="2" cellspacing="2">

                <tr>

                    <td width="150" align="right">

                        User Name

                    </td>

                    <td width="10">

                    </td>

                    <td>

                        <asp:TextBox ID="txtUserName" runat="server" Width="250px"></asp:TextBox>

                    </td>

                </tr>

                <tr>

                    <td width="150" align="right">

                        Password

                    </td>

                    <td width="10">

                        &nbsp;

                    </td>

                    <td>

                        <asp:TextBox ID="txtPasswordName" runat="server" Width="250px"

                            TextMode="Password"></asp:TextBox>

                    </td>

                </tr>

                <tr>

                    <td width="150" align="right">

                        &nbsp;

                    </td>

                    <td width="10">

                        &nbsp;

                    </td>

                    <td>

                        <asp:Button ID="btnSubmit" runat="server" Text="Submit"

                            onclick="btnSubmit_Click" />

                    </td>

                </tr>

            </table>

        </fieldset>

    </div>

    </form>

</body>

</html>

CODE BEHIND

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

 

public partial class UserLogin : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

 

    }

    protected void btnSubmit_Click(object sender, EventArgs e)

    {

 

        Response.Redirect("QuerystringExample.aspx?UserName=" +txtUserName.Text.Trim() + "&Password=" + txtPasswordName.Text.Trim());

 

    }

}

URL

QueryString_Value

Dispaly Login Page(HTML)

<html>

<head id="Head1" runat="server">

    <title>Welcome to Query String Example </title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <h2>

            Display Query String Value Example

        </h2>

        <fieldset style="width: 40%">

            <legend>Display User Login Information</legend>

            <table width="100%" bgcolor="#80AA00" cellpadding="2" cellspacing="2" style="color: #FFFFFF">

                <tr>

                    <td width="150" align="right" valign="middle">

                        User Name

                    </td>

                    <td width="10" valign="middle">

                        :

                    </td>

                    <td>

                        <asp:Label ID="lblUserName" runat="server" Text=""></asp:Label>

                    </td>

                </tr>

                <tr>

                    <td width="150" align="right">

                        Password

                    </td>

                    <td width="10" valign="middle">

                        :

                    </td>

                    <td>

                        <asp:Label ID="lblPassord" runat="server" Text=""></asp:Label>

                    </td>

                </tr>

                <tr>

                    <td colspan="3">

                        &nbsp;

                    </td>

                </tr>

            </table>

        </fieldset>

    </div>

    </form>

</body>

</html>

 

CODE BEHIND

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

 

public partial class QuerystringExample : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

 

        if (Request.QueryString["UserName"].ToString() != null && Request.QueryString["Password"].ToString() != null)

        {

 

             string UserName = Request.QueryString["UserName"];

             string Password = Request.QueryString["Password"];

 

             lblUserName.Text = UserName;

             lblPassord.Text = Password;

 

         

 

        }

    }

}

 

Out Put

c_sharp_query_string_example



Realted Article Headline

How to Pass Query String parameter From DataList
Query String Example in ASP.NET C#
How to increase session time in ASP.Net C#
stroe datatable in session retrive display session vlaues in ASP.Net C #
How to clear Session state in ASP.NET C#
Session state in ASP.NET C#

Article Category

How to create asp.net control dynamically
Learn HTML for beginner
DataList example in C Sharp
Mail sending in asp.net c#
State Management in ASP C #
Basic sql tutorial for Beginner
DataTable example in ASP.Net C#
How to use LINQ in ASP.NET C#
asp.net c # basic tutorial
How to use ajax toolkit in asp.net C#
How to use different types of validation control using asp.net c#
How to use grid view in asp.net c#
Protected by Copyscape Online Plagiarism Detection