QueryString in ASP.NET

QueryString:- 

query string is one of the techniques in Web applications to send data from one webform to another through the URL. A query string consists of two parts, field and value, and each ofpair separated by ampersand (&).

The ? mark in a query string indicates the beginning of a query string and it's value.

There is a limit on the Query string length. Hence, Query string cannot be used to send very long data.

Query strings are visible to the user, hence should not be used to send sensitive information suck as a username and password, unless encrypted.

To retrieve the query string value, use Request object's QueryString property.

Example:-

Step 1: Create two forms in your asp.net project as I have created WebForm1.aspx and WebForm2.aspx

Step 2: Insert two labels and textbox in both forms and button in webform1.aspx as shown below:-

QueryString in ASP.NET



Design form of webform1.aspx:-

 <body>
    <form id="form1" runat="server">
        <div>
            <asp:Table runat="server">
                <asp:TableRow>
                    <asp:TableHeaderCell>
                        <asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
                    </asp:TableHeaderCell>
                    <asp:TableCell>
                        <asp:TextBox ID="TxtName" runat="server"></asp:TextBox>
                    </asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                    <asp:TableHeaderCell>
             <asp:Label ID="Label2" runat="server" Text="City"></asp:Label>
                    </asp:TableHeaderCell>
                    <asp:TableCell>
             <asp:TextBox ID="TxtCity" runat="server"></asp:TextBox>
                    </asp:TableCell>
                </asp:TableRow>             
            </asp:Table>
             <asp:Button ID="Btnid" runat="server" style="margin-left: 96px" Text="Submit" Width="80px" OnClick="Btnid_Click" />
        </div>
    </form>
</body>

Design Form of webform2.aspx:-

<body>
    <form id="form1" runat="server">
        <div>
              <asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
             <asp:TextBox ID="txtname" runat="server"></asp:TextBox>

             <asp:Label ID="Label2" runat="server" Text="City"></asp:Label>
             <asp:TextBox ID="txtcity" runat="server"></asp:TextBox>
        </div>     
    </form>
</body>

Code file of webform1:-

QueryString in ASP.NET


Code file of webform2:-

QueryString in ASP.NET



On button click inserted text of webform1.aspx is send to webform2.aspx using QueryString as shown below:-
QueryString in ASP.NET
QueryString in ASP.NET

















Comments :

Post a Comment