Winform:
Forms.ClassInfo s = new Life365.SanTi.CallCenter.Forms.ClassInfo(); //实例化子窗体类
Form form = this as Form;
form.DialogResult = s.ShowDialog(this);//弹出窗体 this是父窗体对象 运行到此处程序转到子窗体中执行!
if (form.DialogResult == DialogResult.Yes)//如果子窗体传回Yes
{
SelectEmpInfo = s.EmpInfo;//SelectEmpInfo 父窗体变量,子窗体变量
}
子窗体确定按钮中
if (EmpInfo == string.Empty)//子窗体变量判断 可根据实际情况使用
{
this.DialogResult = DialogResult.No;//设置返回值 返回父窗体
}
else
{ this.DialogResult = DialogResult.Yes; }
this.Close();//关闭子窗体
Webform:
父窗体弹出js
var rd = Math.round(Math.random() * 10000);
var retValue = showModalDialog("SelectPersonnel.aspx?i=" + rd + "&siid=" + val, txtEName, 'resizable:yes;scroll:no;status:no;dialogWidth=950px;dialogHeight=500px;center=yes;');//设置弹出窗体和样式
if (retValue) {
var arr = retValue.split("|");
var Name = arr[0];
var id = arr[1];
txtEName.value = Name;
hdEAccount.value = id;
}
子窗体后台
string jsStr = "window.returnValue='" + ret + "';window.close();";//ret 后台局部变量
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "jsStr", jsStr, true);