Related Posts Plugin for WordPress, Blogger...

About

Follow Us

Wednesday, 18 March 2015

We can send multiple values as querystring parameter. Querystring parameters are very helpful when we want to send value from one page to other.
In this article today I am going to explain how we can pass multiple variables using querystring in asp.net
Source Code:
Design Section
   <fieldset style="width:400px">
    <legend>Querystring Example</legend>
    <table>
    <tr><td> Name:</td><td>  <asp:TextBox ID="txtname" runat="server"></asp:TextBox></td></tr>
     <tr><td> 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.Net Section:
   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

Design Section for Next page where we want to receive values:

  <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

0 comments:

Post a Comment