asp.net模态窗口返回值
生活随笔
收集整理的這篇文章主要介紹了
asp.net模态窗口返回值
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
個人感覺模態窗口在做網站的時候,使用到的比較少,前段時間在做項目時要實現以模態窗口傳值和接收返回值,
模態窗口傳值實現比較簡單,但是做好后發現在Chrome瀏覽器中接收不到返回值,修改好Chrome瀏覽器的問題后
大概過了有兩個星期又發現在IE6下會報錯,最終在網上搜索解決辦法才修改好
代碼:
A為父頁面,B為子頁面
A頁面代碼:
//打開選擇客戶的模態窗口function sc(tag) {var recdata = false;var strDialogFeatures = "status=no;center=yes;help=no;dialogWidth=700px;dialogHeight=600px;scroll=yes;resize=no";recdata = showModalDialog("Modal_List_forother.aspx?id=" + tag + "", "newwindow", strDialogFeatures);//此處的if判斷語句必須需要,如果直接用recdata=window.returnValue賦值的話在IE6下會無法獲取到返回值,至于原因,我也不清楚I'M SORRY o(╯□╰)oif (recdata == undefined) {recdata = window.returnValue;}if (recdata != undefined) {//刷新父窗口 此處可以不刷新 因項目功能需要 所以在此處做了刷新操作var url = window.location.href.toString();
//此處省略對變量url的部分操作,根據需要實現的功能不同代碼也會不一樣window.location.href = url;}}
B頁面代碼:
首先在要想在IE6下也能接收模態窗口返回值 先要在B頁面的head部分添加代碼<base target="_self" />
如下:
<head runat="server"><title>子窗口</title><link href="Styles/basic.css" rel="stylesheet" type="text/css" /><base target="_self" /> </head>要想從后臺返回值到父頁面去,我們還需在頁面的cs文件中添加如下代碼:
string strscripts = "";strscripts = strscripts + "<script type=\"text/javascript\">";//這是原先的返回值代碼,也是正確的,只是嫌太長不想用//strscripts = strscripts + " if(window.opener!=undefined){ window.opener.returnValue = '" + name + "'; }else{window.returnValue = '" + name//+ "';} window.close();</script>";strscripts = strscripts + " window.returnValue = '" + name+ "';window.close();</script>";ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script type=\"text/javascript\"> window.returnValue = '" + name + "';window.close();</script>");
?
?
轉載于:https://www.cnblogs.com/xuxw/p/3416455.html
總結
以上是生活随笔為你收集整理的asp.net模态窗口返回值的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JS,JQuery杂谈
- 下一篇: jquery调用asp.net 页面后台