How to pass two parameters from one page to another page?

Posted on 2009-07-08
Last Modified: 2012-05-07

Hello group,

I have started VB.NET/ASP.NET and having a problem. I have a page as index.aspx where user should fill out a form in it. There is a link in the form which pops up a pop-up page and user can select an item. The item's id and description must be pasted or placed into two text-boxes in the main page (index.aspx).

I just learned to use GridView so I have used it in the pop-up page (where the list of products will be shown and user can select an item).

The problem is that although I'm using javascript for passing data but it doesn't pass the parameters to the main page.

Where can I learn this if there is any link or article?

Your help will be appreciated greatly.

Question by:akohan
LVL 53

Assisted Solution

Dhaest earned 100 total points
ID: 24811086
Can you show the code that you are currently using !

Passing information between pages -The .NET way

Passing variables between pages using QueryString
LVL 13

Assisted Solution

kaylanreilor earned 100 total points
ID: 24811118
Client-side techniques use the HTML code and the capabilities of the Web browser to store state-related information. ASP.Net supports the following techniques for storing state information at the client side:
- Query Strings
- Cookies
- Hidden Fields
- View State
You can google all these key words to grab some examples but I think that in your case, probably using Query String should be OK.
For example, imagine you have a textbox and a button on Page1.aspx and you want to display Page2.aspx when the user clicks on the button and pass to it the string contained by the textbox on Page1.aspx... Then you could write the event handler of the button as following:
private void btnSubmit_Click(object sender, System.EventArgs e)


     Response.Redirect('Page2.aspx?myString=" + txtBox.Text);


// in Page2.aspx

private void Page_Load(object sender, System.EventArgs e)


     string myString = Request.QueryString["myString"];


Open in new window

LVL 20

Accepted Solution

ddayx10 earned 300 total points
ID: 24811119
There are certainly lots of ways you might do this. I put together a simple example of how you could extend your javascript a little, and with some clever use of the DOM and window.opener method resolve your issue easily and with no postbacks required. It's really crude for just sample purposes but...

I really don't know what your gridview looks like on your popup (too many possibilities to fathom). This should give you the idea though.
****ASPX MAIN PAGE (No Code Behind Here)****

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">

<head runat="server">

    <title>Main Window</title>

    <script type="text/javascript">

		function popWindow()








    <form id="form1" runat="server">

		<a href="#" onclick="popWindow();return false;">Open PopUp</a><br />

		First Name From Grid Will Go Here: <br />

		<asp:Label ID="lbl1" runat="server" Text="[Place to Put Grid value 1]" /><br /><br />

		Last Name From Grid Will Go Here: <br />

		<asp:Label ID="lbl2" runat="server" Text="[Place to Put Grid value 2]" />





<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">

<head runat="server">

    <title>Popup Window</title>

    <script type="text/javascript">

		function sendValues(element)


			var lbl1 = window.opener.document.getElementById('lbl1'); //gets reference to label on main window

			var lbl2 = window.opener.document.getElementById('lbl2'); //gets reference to label on main window

			var tdNodes = element.parentNode.getElementsByTagName('span'); //gets labels in same row as "select" link = 'red'; = 'red';

			lbl1.innerHTML = tdNodes[0].innerHTML; //gets firstname

			lbl2.innerHTML = tdNodes[1].innerHTML; //gets lastname






    <form id="form1" runat="server">

	<asp:GridView ID="gv" runat="server" AutoGenerateColumns="false">



				<HeaderTemplate>Click Name</HeaderTemplate>


					<asp:Label id="lblFname" runat="server" Text='<%# Eval("fName") %>' />

					<asp:Label id="lblLname" runat="server" Text='<%# Eval("lName") %>' />

					<a href="#" onclick="sendValues(this);return false;">Select</a>








****CODE BEHIND POPUP PAGE (Not needed but I bound the grid here so?****

Imports System.Data.SqlClient

Partial Class Default10

    Inherits System.Web.UI.Page

    Private ReadOnly Property connStr() As String


            Return ConfigurationManager.ConnectionStrings("conn").ToString()

        End Get

    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then bindToGrid()

    End Sub

    Private Sub bindToGrid()

        Dim conn As New SqlConnection(connStr)

        Dim cmd As New SqlCommand("SELECT * FROM DevTable", conn)


        Dim dr As SqlDataReader = cmd.ExecuteReader

        gv.DataSource = dr




    End Sub

End Class

Open in new window


Author Closing Comment

ID: 31601436

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now