Solved

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

Posted on 2009-07-08
4
770 Views
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.


Thanks,
ak
0
Comment
Question by:akohan
4 Comments
 
LVL 53

Assisted Solution

by:Dhaest
Dhaest earned 100 total points
Comment Utility
Can you show the code that you are currently using !

Passing information between pages -The .NET way
http://www.codeproject.com/KB/aspnet/DataPassingBtPages.aspx?fid=109242&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=952258

Passing variables between pages using QueryString
http://www.codeproject.com/KB/aspnet/QueryString.aspx
0
 
LVL 13

Assisted Solution

by:kaylanreilor
kaylanreilor earned 100 total points
Comment Utility
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

0
 
LVL 20

Accepted Solution

by:
ddayx10 earned 300 total points
Comment Utility
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()

		{

			window.open('default10.aspx','newPopUp');

		}

    

    </script>

    

</head>

<body>

    <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]" />

    </form>

</body>

</html>
 
 
 

****ASPX POPUP PAGE****
 

<!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

		}

    

    </script>

</head>

<body>

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

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

		<Columns>

			<asp:TemplateField>

				<HeaderTemplate>Click Name</HeaderTemplate>

				<ItemTemplate>

					<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>

				</ItemTemplate>

			</asp:TemplateField>

		</Columns>

	</asp:GridView>

    </form>

</body>

</html>
 
 

****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

        Get

            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)

        conn.Open()

        Dim dr As SqlDataReader = cmd.ExecuteReader

        gv.DataSource = dr

        gv.DataBind()

        conn.Close()

        conn.Dispose()

    End Sub

End Class

Open in new window

0
 

Author Closing Comment

by:akohan
Comment Utility
Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

772 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

11 Experts available now in Live!

Get 1:1 Help Now