Wednesday, 30 March 2011

Multiple querystring in asp.net


Introduction
With the help of the qurrystring we can also  send the multiples values  from one page to another page. This is very important topic of the ASP.NET.
Implementation
Create page named first.aspx . There is three  textbox and a button in this page. You can see it in the HTML code
HTML  code for first.aspx page

<body>
    <form id="form1" runat="server">
    <div>
   
        &nbsp;&nbsp; Enter your Name :
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br />
&nbsp;
        <br />
&nbsp;&nbsp; Enter Address&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
&nbsp;<br />
        <br />
&nbsp;&nbsp; Enter Email&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
        <br />
        <br />

        <asp:Button ID="Button1" runat="server" onclick="Button1_Click"
            Text="send data to next page" />
&nbsp;&nbsp;
   
    </div>
    </form>
</body>
C# code for first.aspx page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
   // method to send multiple value from querystring

        Response.Redirect("second.aspx?name=" + TextBox1.Text + "&address=" + TextBox2.Text + "&email="+ TextBox3.Text);    }
}


Create page named second.aspx . Drag and drop three  label from toolbox.

HTML  code for second.aspx page

<body>
    <form id="form1" runat="server">
    <div>
   
        &nbsp;&nbsp;<asp:Label ID="lbl_msg" runat="server"></asp:Label>
        <br />
        <br />
        <asp:Label ID="lbl_add" runat="server"></asp:Label>
        <br />
        <br />
        <asp:Label ID="lbl_email" runat="server"></asp:Label>
   
    </div>
    </form>
</body>

C#  code for second.aspx page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class second : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
// method to catch value from querystringat next page
        lbl_msg.Text = Request.QueryString["name"].ToString();
        lbl_add.Text = Request.QueryString["address"].ToString();
        lbl_email.Text = Request.QueryString["email"].ToString();    }
}
Conclusion
Through this article, you have learned how to send multiple  values from one page to another page using querystring.


5 comments: