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

Discussion in 'ASP .Net' started by Paul D. Fox, May 11, 2005.

  1. Paul D. Fox

    Paul D. Fox Guest

    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
     
    Paul D. Fox, May 11, 2005
    #1
    1. Advertising

  2. Paul D. Fox

    Guest

    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
     
    , May 11, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Miller [msft]

    Re: Code Behind vs. no code behind: error

    Ben Miller [msft], Jun 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    592
    Alphonse Giambrone
    Jun 28, 2003
  2. Ramon F Herrera
    Replies:
    8
    Views:
    483
    Pascal J. Bourguignon
    Sep 13, 2009
  3. ramata
    Replies:
    1
    Views:
    187
    Ray Costanzo [MVP]
    May 6, 2005
  4. Jens Peter Hansen
    Replies:
    7
    Views:
    546
    Randy Webb
    Jun 19, 2004
  5. Raffi
    Replies:
    4
    Views:
    230
    Dr John Stockton
    Aug 12, 2004
Loading...

Share This Page