Query String In ASP.NET Web Forms | State Management | ASP.NET | Web Forms

 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="QueryStringDemo_Practice.WebForm1" %>


<!DOCTYPE html>


<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

    <style type="text/css">

        .auto-style1{

            width:400px;

        }

        .auto-style2 {

            width: 129px;

        }

    </style>

</head>

<body>

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

        <div>

            <table cellpadding="4" cellspacing="4" class="auto-style1">

                <tr>

                    <td class="auto-style2">STUDENT ID</td>

                    <td>

                        <asp:TextBox ID="IdTextBox" runat="server" Width="170px"></asp:TextBox>

                    </td>

                </tr>

                <tr>

                    <td class="auto-style2">STUDENT NAME</td>

                    <td>

                        <asp:TextBox ID="NameTextBox" runat="server" Width="170px"></asp:TextBox>

                    </td>

                </tr>

                <tr>

                    <td class="auto-style2">STUDENT AGE</td>

                    <td>

                        <asp:TextBox ID="AgeTextBox" runat="server" Width="170px"></asp:TextBox>

                    </td>

                </tr>

                <tr>

                    <td class="auto-style2">&nbsp;</td>

                    <td>

                        <asp:Button ID="SendButton" runat="server" Text="SEND" Height="41px" OnClick="SendButton_Click" Width="85px"/>

                    </td>

                </tr>

            </table>

        </div>

    </form>

</body>

</html>

Above File is QueryStringDemo_Practice\WebForm1.aspx
















using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace QueryStringDemo_Practice
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void SendButton_Click(object sender, EventArgs e)
        {
            //Response.Redirect("WebForm2.aspx?id=" + IdTextBox.Text + "&name=" + NameTextBox.Text + "&age=" + AgeTextBox.Text);
            //Response.Redirect("WebForm2.aspx?id=" + Server.UrlEncode(IdTextBox.Text) + "&name=" + Server.UrlEncode(NameTextBox.Text) + "&age=" + Server.UrlEncode(AgeTextBox.Text));
            Response.Redirect("WebForm2.aspx?id=" + IdTextBox.Text.Replace("&","%26") + "&name=" + NameTextBox.Text.Replace("&","%26") + "&age=" + AgeTextBox.Text.Replace("&","%26"));


        }
    }
}
Above File is QueryStringDemo_Practice\WebForm1.aspx.cs



















<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="QueryStringDemo_Practice.WebForm2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .auto-style1{
            width:400px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table cellpadding="4" cellspacing="4" class="auto-style1">
                <tr>
                    <td>STUDENT ID</td>
                    <td>
                        <asp:TextBox ID="TextBox1" runat="server" Width="181px"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>STUDENT NAME</td>
                    <td>
                        <asp:TextBox ID="TextBox2" runat="server" Width="181px"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>STUDENT AGE</td>
                    <td>
                        <asp:TextBox ID="TextBox3" runat="server" Width="181px"></asp:TextBox>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>
Above File is QueryStringDemo_Practice\WebForm2.aspx

















using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace QueryStringDemo_Practice
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            TextBox1.Text = Request.QueryString[0];
            TextBox2.Text = Request.QueryString[1];
            TextBox3.Text = Request.QueryString[2];

            //We can also write as shown below:
            //TextBox1.Text = Request.QueryString["id"];
            //TextBox2.Text = Request.QueryString["name"];
            //TextBox3.Text = Request.QueryString["age"];
        }
    }
}
Above File is QueryStringDemo_Practice\WebForm2.aspx.cs






Comments

Popular posts from this blog

Range Validator Control In ASP.NET Web forms | Form Validation | ASP.NET Web forms

Validation Summary Control In ASP.NET Web forms | Form Validation | ASP.NET