ASP.net RaisePostBackEvent not triggered in Chrome works in IE

441 Views Asked by At

I have worked 2 days to fix the issue in the following code and read the all of posts I can find on the internet but none of them can solve my issue.

Here is the codes I work with:

On page AdManager.aspx the related code is:

<%@ 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>
:
:

in AdManager.aspx.cs the code have:

:
:
namespace E6.WebUI {
public partial class AdManager : MasterBasePage {
:
:
    protected void mbAssignResource_OnClose(object sender, EventArgs e) {
        :
        :
    }
:
:
}

in MessageBox.cs the code has:

:
:
[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, "");
       :
       :
    }
:
:
}

in SelectResource.aspx the code has:

 :
 :
 <td>
 <asp:Button ID="SelectButton" runat="server" CssClass="wizardButton" ToolTip="Select" Text="Select"></asp:Button>
 </td>
 :
 :

in SelectResource.aspx.cs the code has:

:
:
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);
    }
}
}

in DialogBase.cs the code has:

:
:
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 is a user control to popup the SelectResourcepage.aspx. when user click the select button on the SelectResourcepage.aspx the function DialogReturn will send the javascript to client to close the MessageBox window and this will trigger the onclose event from the function RaisePostBackEvent() in MessageBox.cs

It works fine for IE but not for Chrome. When I place a stop point in the function RaisePostBackEvent. when the popup window close in IE it hit the stop point. but when the popup window close in Chrome it don't hit the stop point. I added some javascript in the function DialogReturn (those commented out) to see if the script get executed. and it did and I can see the retrunValue in alert(). and the popup window dose close. but the RaisePostBackEvent() don't fire.

I am clueless at this point. Any suggestion? or work around the issue? It is a old code existed for long time my boss want me to fix it because a lot of our user use Chrome we need support it. Thanks Chris

0

There are 0 best solutions below