The Parent Page…

1.       Create a .js file, (MyPopupMaster1.js),  and place the function below in it.   TECH TIP:  Notice we do not have starting and end <script> tags in this file.  Just the function.

 

function OpenMyDialog1()

 

{

 

    //These values will be passed to the Modal Dialog....

    var ParmA = document.getElementById("TextBox1").value;

    var ParmB = document.getElementById("TextBox2").value;

 

 

    var MyArgs = new Array(ParmA, ParmB);

    var WinSettings = "center:yes;resizable:no;dialogHeight:300px"

 

   

 

    //ALTER BELOW LINE - supply correct URL for Child Form

    var MyArgs = window.showModalDialog("dialog1.aspx", MyArgs, WinSettings);

 

 

    //Load the info back when we return from the

    //modal dialog....

    if (MyArgs == null)

    {

        window.alert("Nothing returned from child. No changes made to input boxes")

    }

    else

    {

        //These values will be passed to the Parent Window....

        document.getElementById("TextBox1").value=MyArgs[0].toString();

        document.getElementById("TextBox2").value = MyArgs[1].toString();

    }

}

 

2.       In the asp.net “Parent Page”, add this directive.. (Reference the file your created in Step 1 above)

          <script type="text/javascript" src='MyPopupMaster1.js'></script>

3.       In the asp.net “Parent Page” Code Behind

          Button1.Attributes.Add("onclick", "OpenMyDialog1();return false;"

 

 

 

 

 

 

Place this code in the Child Page…

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Button1.Attributes.Add("onclick", "Done();return false;")

  End Sub

<!-- Notice the doInit function call in the Body -->

 <BODY onload="doInit()">

 

<script language="javascript">

 

function Done() {

 

   // Send the values back to the Parent Page...

 

    var ParmA = document.getElementById("TextBox1").value;

    var ParmB = document.getElementById("TextBox2").value;

 

    var MyArgs = new Array(ParmA, ParmB);

  

    window.returnValue = MyArgs;

    window.close();

}

 

 

 

function doInit() {

 

    // This function will load the values from the

    // Parent page on to the dialog page.

   

    var ParmA = "Aparm";

    var ParmB = "Bparm";

 

    var MyArgs = new Array(ParmA, ParmB);

 

    MyArgs =  window.dialogArguments;

 

    document.getElementById("TextBox1").value = MyArgs[0].toString();

    document.getElementById("TextBox2").value = MyArgs[1].toString();

 

}

 

</script>