asp.net window.showModalDialog 后台用法(兼容谷歌浏览器)

   StringBuilder s = new StringBuilder();
            s.Append("<script language=javascript>");
            s.Append("var a=window.showModalDialog('selectnh.aspx?zhen=" + this.sxdw1.zj + "&cun=" + this.sxdw1.cj + "&zu=" + this.sxdw1.zu + "');");
            s.Append(@"//for chrome 
if(typeof(a) == 'undefined') { 
a = window.returnValue; 
}");
            s.Append("document.getElementById('txtcbfdb').value=a[0];");
            s.Append("document.getElementById('hdnhid').value=a[1];");
            s.Append("</script>");
            Type cstype = this.GetType();
            ClientScriptManager cs =this.ClientScript;
            string sname = "lt";
            if (!cs.IsStartupScriptRegistered(cstype, sname))
                cs.RegisterStartupScript(cstype, sname, s.ToString()); 

父页面

按钮事件代码

StringBuilder s = new StringBuilder();
            s.Append("<script language=javascript>" + "\n");
            s.Append("var result=new Array;  ");
            s.Append("result[0]="+this.ddlnh.SelectedItem.Text+";");
            s.Append("result[1]="+this.ddlnh.SelectedValue+";");
            s.Append(@"//for chrome 
if(window.opener != undefined) {window.opener.returnValue = result;window.opener.close();} else{");
            s.Append("window.returnValue=result;}" + "\n");
           
            s.Append("window.close();" + "\n");
            s.Append("</script>");
            Type cstype = this.GetType();
            ClientScriptManager cs = this.ClientScript;
            string csname = "ltype";
            if (!cs.IsStartupScriptRegistered(cstype, csname))
                cs.RegisterStartupScript(cstype, csname, s.ToString());

子页面 按钮事件代码

下面的传多个值的时候记得加‘’号

 StringBuilder s = new StringBuilder();
                s.Append("<script language=javascript>" + "\n");
                s.Append("var result=new Array(10);  ");
                if (!string.IsNullOrEmpty(model.YWCBHT))
                {
                    s.Append("result[0]=" + model.CBHTBM.Trim() + ";");//合同编码
                }
                else
                {
                    s.Append("result[0]=" + model.JYQZBM.Trim() + ";");//经营权证编码
                }
                NEWLAND.BLL.T_dictionary zdbll = new NEWLAND.BLL.T_dictionary();

                s.Append("result[1]='" + zdbll.Getzd("承包经营权取得方式", model.CBFS).Trim() + "';");//承包方式
                string qzsj = model.CBKSRQ + "至" + model.CBJSRQ;
                s.Append("result[2]='" + qzsj + "';");
                s.Append("result[3]='" + model.CBFMC.Trim() + "';");
                s.Append("result[4]=" + model.LXDH.Trim() + ";");
                s.Append("result[5]='" + zdbll.Getzd("证件类型", model.CBFZJLX).Trim() + "';");
                s.Append("result[6]='" + model.CBFZJHM.Trim() + "';");
                s.Append("result[7]='" + model.CBFDZ.Trim() + "';");
                s.Append("result[8]='" + model.YZBM.Trim() + "';");
                NEWLAND.BLL.DK dkbll = new NEWLAND.BLL.DK();
                DataTable dkbt = dkbll.GetList("cbfdbid='"+this.ddlnh.SelectedValue+"'").Tables[0];
                if (dkbt.Rows.Count > 0)
                {
                    string strs = "共"+dkbt.Rows.Count+"块";
                    decimal htmj = 0;
                    for (int t = 0; t < dkbt.Rows.Count; t++)
                    {
                        try
                        {
                            htmj += decimal.Parse(dkbt.Rows[t]["htmj"].ToString());
                        }
                        catch { }
                    }
                    strs +=htmj+ "亩";
                    s.Append("result[9]='" + strs + "';");
                }
                else
                {
                    string strs = "共0块0亩";
                    s.Append("result[9]='" + strs + "';");
                }

                s.Append(@"//for chrome 
if(window.opener != undefined) {window.opener.returnValue = result;window.opener.close();} else{");
                s.Append("window.returnValue=result;}" + "\n");

                s.Append("window.close();" + "\n");
                s.Append("</script>");
                Type cstype = this.GetType();
                ClientScriptManager cs = this.ClientScript;
                string csname = "ltype";
                if (!cs.IsStartupScriptRegistered(cstype, csname))
                    cs.RegisterStartupScript(cstype, csname, s.ToString());


子页面一定记得在head中加入   <base target="_self" />

发布了68 篇原创文章 · 获赞 6 · 访问量 11万+
展开阅读全文

使用window.showModalDialog()在谷歌浏览器中打不开子窗口

10-11

父窗口相关代码 function funShowDialog(fileName, str_dialogWidth, str_dialogHeight, obj_Text, hid_value, ldObj, parentFieldName) { var path = fileName + "&check=" + hid_value; var SValue = ""; //如果弹选窗为被动对象,且弹出网址中不包含hold_key参数则提示用户选择主动对象 if (funOpenWinIsBD(obj_Text.id.substring(8))) { if (path.indexOf("hold_key=") == -1) { alert("请先选择主动对象!"); return; } } var newwindow = window.showModalDialog(path, "", ";dialogWidth:" + str_dialogWidth + "px;dialogHeight:" + str_dialogHeight + "px;center:1;scroll:0;help:0;status:0;resizable:yes"); var objHidden; if (String(newwindow) != "undefined") { var arrValue = newwindow.toString().split("|"); //value|text if (obj_Text.value != "") { //hold_single=0 if (GetQueryString('hold_single', path) == '0' && confirm("是否累加选择?")) { obj_Text.value = obj_Text.value + ',' + arrValue[1]; objHidden = document.getElementById(obj_Text.id.substring(8)); objHidden.value = objHidden.value + ',' + arrValue[0]; } else { obj_Text.value = arrValue[1]; objHidden = document.getElementById(obj_Text.id.substring(8)); objHidden.value = arrValue[0]; } } else { obj_Text.value = arrValue[1]; objHidden = document.getElementById(obj_Text.id.substring(8)); objHidden.value = arrValue[0]; } 子窗口相关代码 function funReturnValue(strValue) { window.returnValue = strValue; window.close(); } 在父窗口是点击时候弹不出子窗口,在谷歌中弹不出来,在采纳百度上的一些关于解决谷歌兼容性的问题都没用,还是打不开 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览