• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 783
  • Last Modified:

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

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.

3 Solutions
Can you show the code that you are currently using !

Passing information between pages -The .NET way

Passing variables between pages using QueryString
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

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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<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
			lbl1.style.color = 'red';
			lbl2.style.color = '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

akohanAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now