我用下面的方法来实现类似的结果对你的:
在主要页面,我检查,看看是否浏览器可以显示一个模态窗口(基本上,互联网浏览器),如果是这样,流行新的窗口模式 - 这使我返回值直接返回给调用方法,否则我只是弹出一个新窗口,并希望:
if (window.showModalDialog)
{
// showModalDialog returns a result, so pass that into the receiving function
// directly.
CallbackFunctionName(ShowModal(displayPath));
}
else
{
// Just use the standard window.open methods.
ShowWindow(displayPath);
}
function ShowWindow(displayPath)
{
var remoteWin=window.open(displayPath,"EditContact",
"resizable=yes,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,copyhistory=0,modal=yes,width="
+ dialogWidth + ",height=" + dialogHeight);
remoteWin.creator=self;
remoteWin.focus();
}
function ShowModal(displayPath)
{
return window.showModalDialog(displayPath, "editContact",
"center:yes;resizable:no;dialogWidth:" + dialogWidth +
"px;dialogHeight:" + dialogHeight + "px;");
}
然后,在打开的页面上,我再次检查显示模态窗口的能力,如前所述:
if(!window.showModalDialog)
{
// Call the callback method directly
window.opener.CallBackFunctionName(resultValue);
}
else
{
// Return the value back to the caller, who will pass the result along.
window.returnValue=resultValue;
}
self.close();
ASP。NET只以已知的方式使用控件ID进行混淆 - 一旦控件已由运行时加载到服务器上,您可以检索将包含控件的运行时ID的ClientID
- 您可以将此值写入JS变量,或者使用一些JS根据控件的其他功能来获取控件值。
还要注意的是,从ASP.NET框架的第4版开始,您可以设置控件的ClientIdMode
以更好地控制生成Ids的方式。