Pass multiple variables using Querystring in asp.net - Free Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server,WCF,Entity framework snippets and tutorial

Pass multiple variables using Querystring in asp.net

Introduction: In this article today I am going to explain how we can pass multiple variables using querystring in asp.net

Description:


HTML markup of First page:
   <fieldset style="width:400px">
    <legend>Querystring Example</legend>
    <table>
    <tr><td>Book Name:</td><td>  <asp:TextBox ID="txtname" runat="server"></asp:TextBox></td></tr>
     <tr><td>Book Price:</td><td><asp:TextBox ID="txtprice" runat="server"></asp:TextBox></td></tr>
    <tr><td></td><td><asp:Button ID="btnsend" runat="server" Text="Send Email" onclick="Button1_Click" /></td></tr>    
    </table>
    </fieldset>

On button click write the given code (C#):
protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("webform2.aspx?bname="+txtname.Text+"&bprice="+txtprice.Text);   
    }


VB:
   Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles btnsend.Click
        Response.Redirect("default2.aspx?bname=" + txtname.Text + "&bprice=" + txtprice.Text)
    End Sub


Html Markup of Second page where get the value:

  <table>
    <tr><td>Book Name:</td><td><asp:Label ID="lblbname" runat="server" Text=""></asp:Label></td></tr>
     <tr><td>Book Price:</td><td><asp:Label ID="lblprice" runat="server" Text=""></asp:Label></td></tr>
    <tr><td></td><td></td></tr>    
    </table>

Write the below given code to get the value (C#):
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            lblbname.Text = Request.QueryString["bname"];
            lblprice.Text = Request.QueryString["bprice"];
        }
    }

VB:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        If Not IsPostBack Then
            lblbname.Text = Request.QueryString("bname").ToString()
            lblprice.Text = Request.QueryString("bprice").ToString()
        End If

    End Sub

Output :

Is this article helpful for you?

If yes post your comment to appreciate my work and fell free to contact me. You can like me on Facebook, Google+, Linkedin and Twitter via hit on Follow us Button and also can get update follow by Email.

What do you think about this article?

If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.

Share this

Share on FacebookTweet on TwitterPlus on Google+


EmoticonEmoticon