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.


7 comments:

  1. Matur Nuwun....

    ReplyDelete
  2. t is really a great work and the way in which u r sharing the knowledge is excellent.
    Thanks for helping me to understand basic concepts. As a beginner in dot net programming your post help me a lot.Thanks for your informative article.Dot Net training in chennai | Dot Net training institutes in chennai | Dot Net training in velachery

    ReplyDelete

  3. Its a wonderful post and very helpful, thanks for all this information.
    ASP.Net Training in Delhi

    ReplyDelete
  4. Thanks a lot. You have done an excellent job. I enjoyed your blog . Nice efforts.
    Visit us: Dot Net Training Online India
    Visit us: .Net Online Training Hyderabad

    ReplyDelete
  5. Lakshya IAS Academy is a well-known Institute and the Best UPSC in Mumbai preparing candidates for the Civil Services Examination. It is one of the known IAS coaching centers in Mumbai, which is known for offering high-quality guidance to aspirants.

    ReplyDelete