我已经工作了 2 天来解决以下代码中的问题,并阅读了我可以在互联网上找到的所有帖子,但没有一个可以解决我的问题。
这是我使用的代码:
在 AdManager.aspx 页面上,相关代码为:
<%@ Register TagPrefix="MB" Namespace="E6.WebUI.MessageBox" Assembly="E6.WebUI" %>
:
:
<asp:UpdatePanel ID="upnlContent" runat="server" UpdateMode="Conditional">
<ContentTemplate>
:
:
<td align="Center">
<MB:MessageBox ID="mbAssignResource" runat="server" CssClass="wizardLinkButtonYellow" DialogWidth="500" DialogHeight="370" DialogName="DialogBoxes/SelectResource.aspx" Text="Assign Resource" DefaultValue="" OnOnClose="mbAssignResource_OnClose"></MB:MessageBox>
</td>
:
:
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="tree" EventName="NodeClick" />
<asp:AsyncPostBackTrigger ControlID="btnDeleteNode" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="btnAddNode" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="popupAdPositionSelect" EventName="AddClick" />
<asp:AsyncPostBackTrigger ControlID="popupAdSelect" EventName="AddClick" />
<asp:AsyncPostBackTrigger ControlID="ddlViewBase" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
:
:
在 AdManager.aspx.cs 中,代码有:
:
:
namespace E6.WebUI {
public partial class AdManager : MasterBasePage {
:
:
protected void mbAssignResource_OnClose(object sender, EventArgs e) {
:
:
}
:
:
}
在 MessageBox.cs 中,代码具有:
:
:
[DefaultProperty("Text"), ToolboxData("<{0}:MessageBox runat=server></{0}:MessageBox>")]
public class MessageBox : WebControl, IPostBackEventHandler
{
:
:
[Description("The event which indicates when the dialog is closed.")]
public event EventHandler OnClose;
:
:
public void RaisePostBackEvent(String eventArgument)
{
if (OnClose != null)
{
OnClose(this, new MessageBoxEventArgs(eventArgument));
}
}
protected override void OnInit(EventArgs e)
{
// Guarantee that the __doPostBack function is defined
this.Page.ClientScript.GetPostBackEventReference(this, "");
:
:
}
:
:
}
在 SelectResource.aspx 中,代码具有:
:
:
<td>
<asp:Button ID="SelectButton" runat="server" CssClass="wizardButton" ToolTip="Select" Text="Select"></asp:Button>
</td>
:
:
在 SelectResource.aspx.cs 中,代码具有:
:
:
namespace E6.WebUI
{
/// <summary>
/// Summary description for SelectResource.
/// </summary>
public class SelectResource : DialogBase
{
:
:
private void InitializeComponent()
{
:
:
this.SelectButton.Click += new System.EventHandler(this.SelectButton_Click);
:
:
}
:
:
private void SelectButton_Click(object sender, System.EventArgs e)
{
:
:
DialogReturn(Resources.Items[Resources.SelectedIndex].Value);
}
}
}
在 DialogBase.cs 中,代码具有:
:
:
public class DialogBase : PageBase
{
public void DialogReturn(string returnValue)
{
// Set the value for the return object and close the dialog
StringBuilder script = new StringBuilder("<script language='javascript'>\n");
if (returnValue != null)
{
// clean return value
string cleanReturnValue;
cleanReturnValue = returnValue;
cleanReturnValue = cleanReturnValue.Replace("'", "\\'");
// once clean, append
script.Append("top.window.returnValue='");
script.Append(cleanReturnValue);
script.Append("';\n");
}
//script.Append(" if(window.chrome) { alert('chrome'); __doPostBack('ctl00$contentPH$mbAssignResource', top.window.returnValue); alert(top.window.returnValue); }");
//script.Append(" __doPostBack('ctl00$contentPH$mbAssignResource', top.window.returnValue); ");
script.Append("top.window.close();\n");
script.Append("</script>");
ScriptManager.RegisterStartupScript(this, this.GetType(), "MsgBox", script.ToString(), false);
}
:
:
}
MessageBox 是一个弹出SelectResourcepage.aspx 的用户控件。当用户单击 SelectResourcepage.aspx 上的选择按钮时,DialogReturn 函数将向客户端发送 javascript 以关闭 MessageBox 窗口,这将触发 MessageBox.cs 中函数 RaisePostBackEvent() 的 onclose 事件
它适用于 IE,但不适用于 Chrome。当我在函数 RaisePostBackEvent 中放置一个停止点时。当弹出窗口在 IE 中关闭时,它会到达停止点。但是当 Chrome 中的弹出窗口关闭时,它不会到达停止点。我在函数 DialogReturn 中添加了一些 javascript(那些被注释掉的)来查看脚本是否被执行。确实如此,我可以在 alert() 中看到 rerunValue。并且弹出窗口关闭。但 RaisePostBackEvent() 不会触发。
在这一点上我一无所知。有什么建议吗?或解决这个问题?这是一个存在很长时间的旧代码,我的老板希望我修复它,因为我们的很多用户都使用 Chrome,我们需要支持它。谢谢克里斯