100分求高人指点:showModalDialog问题.

kafree_0 2007-01-22 04:51:24
在一个主页面上,原来通过点击一个按钮,用Response.Redirect("..")转到一个B页面上,选择一个值,然后把值返回到主页面上,是OK的,
现在把B页面作为一个对话框弹出,然后选值返回到主页面上提示脚本错误.
是什么原因造成的?
以下是部分代码:
主页面上的调用:
btn.Attributes.Add("onclick", "javascript:openModalWin('../report/Rpt_AssetCategory.aspx','catSearch','320','550');");

子页面上的选择按钮代码:
private void btnSelect_Click(object sender, System.EventArgs e)
{
string returnId =this.Request.QueryString["id"];
System.Text.StringBuilder script = new System.Text.StringBuilder();
script.Append("<script language='javascript'>" + "\n");
script.Append("dataProc('"+ returnId +"','"+ SelectedCate + "');");
script.Append("</script>" + "\n");
this.RegisterStartupScript("SelectedCate",script.ToString());

//页面之间传递Session变量
Session["SelectedCate"] = SelectedCate;

JS中用到的2个函数
function openModalWin(pageName,returnParameter,subWindowWidth,subWindowHeight)
{
var mainWindowHeight = screen.height;
var mainWindowWidth = screen.width;
var windowTop = Math.floor((mainWindowHeight- subWindowHeight)/2);
var windowLeft = Math.floor((mainWindowWidth - subWindowWidth)/2);
var windowOpen = window.showModalDialog(pageName +"?id=" + returnParameter,window,'dialogWidth:'+ subWindowWidth +'px;dialogHeight:'+ subWindowHeight +'px;dialogTop='+ windowTop +';dialogLeft='+ windowLeft +';toolbar=yes;resizable=yes;scrollbars=yes');
}

function dataProc(strControlName,strSelectValue)
{
var parentWin = getParentWindow();
if (!(parentWin == null ))
{
window.dialogArguments.document.getElementById(strControlName).value=strSelectValue;
top.close();
}
}

...全文
323 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
midymidy 2007-01-24
  • 打赏
  • 举报
回复
可能是定义的问题
kafree_0 2007-01-24
  • 打赏
  • 举报
回复
解决了,代码是完全正确的,不是代码的问题
leohuang 2007-01-23
  • 打赏
  • 举报
回复
要么就这样
在主窗体中写

var v = window.showModalDialog(....);
document.getElementById(strControlName).value=v;
kafree_0 2007-01-23
  • 打赏
  • 举报
回复
回复liangxf0022(小新)

哪些没有执行,能具体说一下吗?谢谢
-
kafree_0 2007-01-23
  • 打赏
  • 举报
回复
回复leohuang(LEO)
去掉也是一样的错误啊
回复liangxf0022(小新)
我看一下
liangxf0022 2007-01-23
  • 打赏
  • 举报
回复
在showModalDialog中,你不可以操作父窗体的内容。

父界面上的js已经停止执行了,只有在当前这个窗体关闭以后才继续执行后面的语句。
leohuang 2007-01-23
  • 打赏
  • 举报
回复
可以去掉parentWin判断
-----------------------------------------------------
eg:

function dataProc(strControlName,strSelectValue) {
window.dialogArguments.document.getElementById(strControlName).value=strSelectValue;
window.close();
}
kafree_0 2007-01-23
  • 打赏
  • 举报
回复
因为原来跳转页面的时候是可以用的,改成弹出的就有问题了,我想知道差别在哪里
kafree_0 2007-01-23
  • 打赏
  • 举报
回复
function getParentWindow()
{
if (top.opener) {
return top.opener;
}
else if (top.dialogArguments) {
return top.dialogArguments;
}
}
liangxf0022 2007-01-23
  • 打赏
  • 举报
回复
getParentWindow是自己写的方法么?好像没这个默认方法吧?

一般都是用window.returnValue = xxxx来返回结果。

然后在showModalDialog后面处理返回结果
rtl = window.showModalDialog();
// 接着继续处理
msgbox(rtl);

kafree_0 2007-01-22
  • 打赏
  • 举报
回复
补充一个错误提示:

行: 86
字符: 1
错误:缺少对象
代码: 0
URL:http://localhost/view/report/Rpt_AssetCategory.aspx?id=catSearch
kafree_0 2007-01-22
  • 打赏
  • 举报
回复
回复BookSirSwordsMan(书生剑客)

top.close();是弹出日期那个对话框,选完日期后自动关闭的,注释掉问题依旧,应该不是这个的问题.
devilok 2007-01-22
  • 打赏
  • 举报
回复
BookSirSwordsMan 2007-01-22
  • 打赏
  • 举报
回复
top.close();总觉得这句有问题
kafree_0 2007-01-22
  • 打赏
  • 举报
回复
看过的帮忙顶一下`多谢
yzaiml 2007-01-22
  • 打赏
  • 举报
回复
模式会话
qzrqzr 2007-01-22
  • 打赏
  • 举报
回复
学习

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧