showModalDialog 子窗口向父窗口传递数组,js的使用

父窗口代码:

js:

<script language="JavaScript">



        function getProSaleOrder() {

            var vReturnValue = window.showModalDialog('SearchProSaleOrder.aspx', window, 'dialogWidth=900px;dialogHeight=500px;status=no');



            if (vReturnValue !== "" && vReturnValue !== undefined) {

                document.getElementById("receipBillCode").value = vReturnValue[0];

                document.getElementById("busiName").value = vReturnValue[1];

                document.getElementById("shouReciAmount").value = vReturnValue[2];

            }

        }

      </script>

调用js的地方:

<image   src="../Images/search.png"  onclick="getProSaleOrder(document.all.receipBillCode)";  style="CURSOR: hand"  alt="请查找" >

子窗口代码:

js:

<script language="JavaScript">



        function returnSelect() {

            var retArr = new Array();

            retArr[0] = arguments[0];

            retArr[1] = arguments[1];

            retArr[2] = arguments[2];

            window.returnValue = retArr;



            window.close();

        }

    </script>

 

 

 子窗口的后台事件中调用该js的地方:

 //GridView1_RowDataBound事件   双击返回值

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

    {

        if (e.Row.RowType == DataControlRowType.DataRow)

        {

            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#9CCBF7';this.style.cursor='hand'");

            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");



            //注意格式,是单引号加双引号,否则会提示“常量中有换行符”

            //string[] sel = { e.Row.Cells[0].Text.ToString(), e.Row.Cells[1].Text.ToString(), e.Row.Cells[2].Text.ToString() };

            //Response.Write(sel[0]);

            //e.Row.Attributes.Add("ondblclick", "returnSelect(sel);");

            e.Row.Attributes.Add("ondblclick", "returnSelect( '" + e.Row.Cells[0].Text.ToString() + "','" + e.Row.Cells[1].Text.ToString() + "','" + e.Row.Cells[2].Text.ToString() + "')");

          

        }



    }

 

注意这里传递数组的方法:js函数returnSelect()里面并没有参数,获得数组是在函数里面获得的,后台传值的时候也是直接罗列的。

 

 

 

 

原来我按照自己的思路是这么做的:

js:

<script language="JavaScript">



        function returnSelect(retArr) {

                      window.returnValue = retArr;



            window.close();

        }

    </script>

后台调用传值:

 //GridView1_RowDataBound事件   双击返回值

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

    {

        if (e.Row.RowType == DataControlRowType.DataRow)

        {

            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#9CCBF7';this.style.cursor='hand'");

            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");



            

            string[] sel = { e.Row.Cells[0].Text.ToString(), e.Row.Cells[1].Text.ToString(), e.Row.Cells[2].Text.ToString() };

            

            e.Row.Attributes.Add("ondblclick", "returnSelect(sel);");

           

          

        }



    }

这里我按照c#的编程方法想当然的传递参数,结果js里面提示错误“"retArr"未定义”

你可能感兴趣的:(showModalDialog)