Passing parameters to a Popup Window and getting them in Code-Behind

P

Paul D. Fox

I'm trying to launch a Child Window from a hyperlink on a Datagrid and have
it recieve multiple values from the Parent Window. Upon recieving the
values in the Child Window, I need to access them in the code-behind so I
can render a datagrid in the Child. I've tried just doing another Postback
in the child's onLoad event but I get a Javascript error. Is there another
way to do this?

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="ChildWin.aspx.vb"
Inherits="PTTimesheet.ChildWin"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>ChildWin</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<pt:styleSheets xmlns:pt="http://www.plumtree.com/xmlschemas/ptui/" />
<script language="javascript">
function doInit()
{
var intPayrollPeriodID;
var strContactID;
var intTimesheetID;

var parentArgs = new
Array(intPayrollPeriodID,strContactID,intTimesheetID);
parentArgs = window.dialogArguments;

intPayrollPeriodID = parentArgs[0].toString();
strContactID = parentArgs[1].toString();
intTimesheetID = parentArgs[2].toString();

alert("Recieving: " + intPayrollPeriodID + "|" + strContactID + "|" +
intTimesheetID);

window.execScript("__doPostBack('BindDataGrid','" + parentArgs +
"')","JavaScript");
}
</script>
</HEAD>
<body onLoad="doInit();">
<form id="PTTimesheet_Detail" method="post" runat="server">
<asp:Label id="lblPayrollPeriodID" runat="server"></asp:Label>
<asp:Label id="lblContactID" runat="server"></asp:Label>
<asp:Label id="lblTimesheetID" runat="server"></asp:Label>
</form>
</body>
</HTML>

Paul
 
B

billmiami2

Paul,

Include a javascript function in your calling page like this:

<script language=javascript>
function opendialog(dlglocation, querystring, dlgheight, dlgwidth,
dlgtop, dlgleft){
var
dialogposition='width='+dlgwidth+',height='+dlgheight+',top='+dlgtop+',left='+dlgleft;
if (querystring!=null){
dialoglocation+='?'+querystring;
}
var NewWindow = window.open(dialoglocation,'dialog',dialogposition);
if (NewWindow.focus!=null){
NewWindow.focus();
}
}
</script>

Where

dlglocation is the URL of the child window you would like to open
querystring is a querystring containing parameters you would like to
pass to the child
dlgheight, dlgwidth, dlgtop, dlgleft are the height, width, distance
from top and distance from left of the child window, respectively.

Normally, I place functions like this in a VB (or C#) component and add
them to the page as necessary with Page.RegisterClientScript. In this
way, you have a central repository of javascript functions.
From a link on your calling page, call the opendialog function above
grabbing parameter values on the way:

<asp:hyperlink runat=server id="lnkopenchildwindow" navigateurl=<%#
"javascript:eek:pendialog('dialogs/dlgcomplainants.aspx','parameter1=" &
tbparameter1.text & "&parameter2=" &
tbparameter2.text',400,410,.5*(screen.height-400),.5*(screen.width-410));"
%>

In the code behind for the child, pick up the parameters from the
querystring and do something with them

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
'Get parameters from the query string if they exist
If Request.QueryString("parameter1") <> "" Then
tb1.Text = Request.QueryString("parameter1")
End If

If Request.QueryString("parameter2") <> "" Then
tb2.Text = Request.QueryString("parameter2")
End If

End If
End Sub

I hope this helps you.

Bill E.
Hollywood, FL
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top