Wednesday 8 October 2014

QueryString in Asp.Net C#

No comments    
categories: ,
QUERYSTRING


Pass the Values using QueryString One Page to Another page in Asp.Net C#

  A querystring is a set of characters input to a computer or Web browser and sent to a queryprogram to recover specific information from a database .

                    DEMO









Html Coding for Design Page


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>  
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
        <tr><td>
            <asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
            </td><td>
                <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
            </td></tr>
        <tr><td class="auto-style1">
            <asp:Label ID="Label2" runat="server" Text="Age"></asp:Label>
            </td><td class="auto-style1">
                <asp:TextBox ID="txtAge" runat="server"></asp:TextBox>
            </td></tr>
        <tr><td>
            <asp:Label ID="Label3" runat="server" Text="Mobile Number"></asp:Label>
            </td><td>
                <asp:TextBox ID="txtMobile" runat="server"></asp:TextBox>
            </td></tr>
        <tr><td colspan ="2">
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Send" />
</td></tr>
    </table>
    </div>
    </form>
</body>
</html>
Html Coding for Home Page


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>   
        WELCOME TO HOMEPAGE<br />
        <br />
        <br />
        <asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>

        <asp:Label ID="lblName" runat="server" Text="Label"></asp:Label>
        <br />
        <br />
        <asp:Label ID="Label2" runat="server" Text="Age"></asp:Label>

        <asp:Label ID="lblAge" runat="server" Text="Label"></asp:Label>
        <br />
        <br />
        <asp:Label ID="Label3" runat="server" Text="Mobile"></asp:Label>

        <asp:Label ID="lblMobile" runat="server" Text="Label"></asp:Label>
        <br />
        <br />
        </div>
    </form>
</body>
</html>




Individual Values Passing 


  Response.Redirect("homepage.aspx?Name=" + txtName.Text);

                            or

 Response.Redirect("homepage.aspx?Age=" + txtAge.Text);

                            or

  Response.Redirect("homepage.aspx?Mobile=" + txtMobile.Text);



Multiple Values Passing


Response.Redirect("homepage.aspx?Name=" + txtName.Text+"&Age="+txtAge.Text+"&Mobile="+txtMobile.Text);




C# Coding Multiple Values Passing



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

public partial class queryStrin : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        txtName.Text = "DotNet";
        txtAge.Text = "29";
        txtMobile.Text = "0123456789";

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        Response.Redirect("homepage.aspx?Name=" + txtName.Text + "&Age=" + txtAge.Text + "&Mobile=" + txtMobile.Text);

    }
}






C# Coding for Individual Values Passing 

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

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

        lblAge.Text = Request.QueryString["Age"].ToString();

        lblName.Text = Request.QueryString["Name"].ToString();

        lblMobile.Text = Request.QueryString["Mobile"].ToString();


    }


}











                           




                                         

0 comments:

Post a Comment