views:

61

answers:

4

I would like to add some variables when my window.open function fires.

Example:

<a href="javascript:void(window.open('Details.aspx', 'Title'))"><%# Eval("Id").ToString) %></a>

I would like to pass the id number to the Details.aspx page. How do I do that?

+1  A: 

pass the value as a query string

<a href="javascript:void(window.open('Details.aspx?id=<%# Eval("Id").ToString) %>', 'Title'))"><%# Eval("Id").ToString) %></a>
John Hartsock
A: 

Pass it in the query string or fragment, and parse it on the other page.

Ignacio Vazquez-Abrams
+4  A: 

Pass it on the query string:

<a href="javascript:void(window.open('Details.aspx?id=<%# Eval("Id").ToString) %>', 'Title'))"><%# Eval("Id").ToString) %></a>

In Details.aspx you will be able to get it:

var id = Request.QueryString["id"];
Oded
A: 

You can reference variables in the parent page from the child page via window.opener. Your parent page would have script something like this:

var detailsId = 0;
function openDetails(id)
{
    detailsId = id;
    window.open('Details.aspx', 'Title');
}

and HTML something like this:

<a href="javascript:void(openDetails('<%# Eval("Id").ToString) %>'))">
    <%# Eval("Id").ToString) %></a>

And your child page could get the id in script like this:

var id = window.opener.detailsId;

enjoy!

gilly3