Search code examples
javascriptjqueryasp.netcolorbox

Closing jquery modal window conditionally from ASP.net code-behind


I have an ASP.net page with a link to open a jquery-based modal window (that uses colobox jquery plugin). The content of that window in loaded from another aspx file (it loads an iframe). I want to close that window when the user presses an asp:button and if some condition in my code-behind went well.

I tried many ways to close that window from code-behind like these ways:

Page.RegisterStartupScript("X", @"$(this).dialog('close');");

Page.RegisterStartupScript("X", @"var win = window.open('','_self'); win.close();");

btnDone.Attributes.Add("onclick", @"var win = window.open('','_self'); win.close();");

btnDone.Attributes.Add("onclick", @"window.open('../px/nsk.aspx', '_self', null); window.close(); ");

System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE='JavaScript'>");
            System.Web.HttpContext.Current.Response.Write("self.close();");
            System.Web.HttpContext.Current.Response.Write("</SCRIPT>");

but non of them can close that modal window. I'm testing on latest version of firefox. the code behind can be supposed as sth like this:

    // do some database works
if (condition)
{
   // close this modal window
}

I also tried methods from jquery but none of them were a success. Can you please telling me how can I close this window?


Solution

  • The problem seams to be solved this way:

        Page.ClientScript.RegisterStartupScript(GetType(), 
            "CloseKey", "parent.$.colorbox.close();", true);