模态子窗体的向父窗体返回数据(ShowModalDialog)

一.添加父窗体JavaScript代码,“showInfo()”方法用于打 开子窗体,并获取子窗体返回结果填充到TextBox1和TextBox2

<script language="javascript" type="text/javascript">

    function showInfo()

    {

        var retValue=window.showModalDialog
        ('Child.aspx','','scroll=yes;dialogWidth=50;dialogHeight=40');

        document.all('<%=TextBox1.ClientID%>').value=retValue[0];

        document.all('<%=TextBox2.ClientID%>').value=retValue[1];

    }

</script>

二.子窗体服务器端提交数据以数组形式返回到父窗体中,例为 Button1按钮

 

 

 

protected void Button1_Click(object sender, EventArgs e)

{

string scode = "var arr=new Array();arr[0]='aaa';arr[1]='bbb';
window.parent.returnValue=arr;window.parent.close();"
;

string script = string.Format("<script language='javascript' type='text/javascript'>{0}</script>",scode);

Page.RegisterStartupScript("close",script);

}

<!--[endif]-->

<!--[endif]-->

或在子窗体客户端提交数据以数组形式返回到父窗体中:

 

<script type="text/javascript" language="javascript">

function ReturnValue()

{

var arr=new Array();arr[0]='aaa';arr[1]='bbb';

window.parent.returnValue=arr;window.parent.close();

}

</script>

 

<input type="button" id="button2" value="Click" onclick="ReturnValue()"/>

 

你可能感兴趣的:(showModalDialog)