【发布时间】:2013-03-20 18:49:23
【问题描述】:
我有一个主“报告”页面,其中包含用户可以执行的一些操作,这些操作将打开一个模态 RadWindow,让用户执行操作,然后单击“保存”,模态窗口将关闭并且主网格刷新。
这在 IE 和 Firefox 中都可以正常工作,但 Chrome 会完成所有“工作”,但模式页面保持打开状态。仅当我点击“保存”按钮时,这才是正确的;表单顶部的取消按钮和关闭按钮仍然可以正常工作。
这是来自子窗口的 JavaScript:
<script type="text/javascript">
function GetRadWindow() {
var oWindow = null;
if (window.radWindow)
oWindow = window.radWindow;
else if (window.frameElement.radWindow)
oWindow = window.frameElement.radWindow;
return oWindow;
}
function CloseRadWindow() {
var oWnd = GetRadWindow()
oWnd.SetUrl("");
oWnd.close();
}
function CloseAndRebind(args) {
var oWnd = GetRadWindow()
oWnd.BrowserWindow.refreshGrid(args);
oWnd.SetUrl("");
oWnd.close();
}
</script>
这是父级的refreshgrid函数:
<script type="text/javascript">
function refreshGrid(arg) {
if (!arg) {
$find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest("Rebind");
}
else {
$find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>").ajaxRequest("RebindAndNavigate");
}
}
</script>
父级通过运行加载模态窗口:
protected void btnSplitInvoice_Click(object sender, EventArgs e)
{
var btn = sender as Button;
var item = (GridDataItem)btn.Parent.Parent;
long id = long.Parse(item["Id"].Text);
var itemType = this.TabStrip1.SelectedIndex == 0 ? "TransferOrderInvoice" : "EquipmentInvoice";
string scriptstring = "var oWindow=radopen('../Misc/SplitInvoice.aspx?id=" + id + "&type=" + itemType + "','SplitInvoice');oWindow.SetModal(true);";
ScriptManager.RegisterStartupScript(this, this.GetType(), "openwindow", scriptstring, true);
}
孩子的保存按钮在后面的代码中做了很多工作,然后就这样结束了:
ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "mykey", "CloseAndRebind('navigateToInserted');", true);
取消按钮是这样设置的:
<button type="button" class="CancelBtn" value="" onclick="CloseRadWindow()">
</button>
我发现不久前有一个条目建议在结尾添加window.open('', '_self', '');,但这似乎不适用(而且当我测试它时也不起作用)。
编辑:在控制台打开的情况下运行 Chrome 时,我确实看到当 refreshgrid 运行时我在主页上遇到错误:
Cannot call method 'ajaxRequest' of null
但不确定这是否是导致问题的原因。现在进一步研究。
EDIT2:所以问题似乎是在使用 Chrome 时,在 refreshGrid 运行时似乎没有找到主页面中的 RadAjaxManager,这就是上述 null 错误的原因。我能够通过用document.location.reload(); 替换 refreshGrid 函数的胆量来“解决”这个问题,而且效果很好。不过,如果我能提供帮助,我宁愿不重新加载整个页面,所以想知道是否有办法解决这个问题。我很好奇为什么 IE 和 Firefox 似乎可以处理这个问题,而 Chrome 却没有?
更多可能有用的信息:主页的 Page_Load 事件:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.Session["AllUserLocationValue"] = string.Empty;
this.InitializeThePage();
}
RadAjaxManager manager = RadAjaxManager.GetCurrent(this.Page);
manager.AjaxRequest += this.manager_AjaxRequest;
manager.AjaxSettings.AddAjaxSetting(manager, this.pnlHeading, this.RadAjaxLoadingPanel1);
manager.AjaxSettings.AddAjaxSetting(manager, this.RadCodeBlock1, this.RadAjaxLoadingPanel1);
}
【问题讨论】:
标签: c# javascript asp.net telerik