主體WEB頁中:
private void Page_Load(object sender, System.EventArgs e)
{
string strScript="<script language=\"javascript\">\n"
//-------------------------------------------------單個值返回
strScript += "function GetValue(InfoA,InfoB){\n";
strScript += "var strID=window.showModalDialog('PopForms/TestPop.aspx?ParamA='+InfoA+'&ParamB='+InfoB,null,";
strScript +="'dialogWidth:450px;dialogHeight:480px;center:1;scroll:1;help:0;status:0;resizable:no;')\n";
strScript += "if (strID!=undefined)\n document.all['" + txtText.ClientID + "'].value=strID;\n" ;//結果strID賦值給txtText
strScript += "}\n"; //如果返回的是數組
//------------------------------------------------ 多值返回
sbScript.Append("function OpenEditLot(){\n");
sbScript.Append("var strID=window.showModalDialog('PopForms/Test.aspx?myTime='+Date(),null,");
sbScript.Append("'dialogWidth:433px;dialogHeight:450px;center:1;scroll:1;help:0;status:0;resizable:no;')\n");
sbScript.Append("if(strID!=undefined) {document.all['" + TxtA.ClientID + "'].value=strID[0]\n");
sbScript.Append(" document.all['" + TxtB.ClientID + "'].value=strID[1]\n");
sbScript.Append(" document.all['" + TxtC.ClientID + "'].value=strID[2]\n}");
sbScript.Append("}\n");
// more and here....
//-------------------------------------------------
strScript += "</script>";
this.Page.RegisterClientScriptBlock("clientScript", strScript);
if(!IsPostBack)
{
btnTest.Attributes["onclick"] = "GetValue(document.all('"+txtA.ClientID+"').checked,document.all('"+
txtB.ClientID+"').value)";
}
}
彈出WEB頁中:
1.HTML中定義返回函數,供在頁面中調用返回函數
<HEAD>
<title>QueryLot</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<LINK href="../../WebControler/ICMES.css" type="text/css" rel="stylesheet">
<base target="_self">
<script language="javascript">
function ReturnValue(PamA,PamB,PamC)
{
var my_array = new Array(PamA, PamB,PamC);
window.returnValue = my_array;
window.close();
}
</script>
</HEAD>
2.在頁面中調用返回函數
//用按鈕返回
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
btnReturn.Attributes["onclick"] = "ReturnValue('"+ValueA+"','"+ValueB+"','"+ValueC+"')";
}
}
//用DataGrid點擊返回
private void dbGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.DataSetIndex != -1)
{
e.Item.Cells[0].Attributes["onclick"] = "ReturnValue('"+e.Item.Cells[0].Text+"','"+e.Item.Cells[1].Text+"','"+
e.Item.Cells[2].Text+"')";
e.Item.Cells[0].CssClass = "";//引用點擊時的CSS樣式文件
}
}
3.無返回值的返回
private void btnCancel_Click(object sender, System.EventArgs e)
{