Q:

I dont get redirected instead I get: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

I have a dialog which I need to commit so it disappear and then redirect else the redirect will happen inside the dialog.
I have this following method that do not work anymore:
private void CommitPopupAndRedirect(string url)
{
   var script = string.Format("<script type='text/javascript'>parent.window.location='{0}';window.frameElement.commitPopup();</script>", url);
   Context.Response.Write(script);
   Context.Response.Flush();
   Context.Response.End();
}

I am recieving this exception my catch:

Unable to evaluate expression because the code is optimized or a
  native frame is on top of the call stack.

What happens is the dialog disappear and then a refresh happens on the site, no redirect.
I have googled abit and I found 
HttpContext.Current.ApplicationInstance.CompleteRequest();

But it still didnt work.
Any kind of help is appreciated alot!

A:

you need to use RegisterStartupScript for more information, please review:
Call jQuery function from ASP.NET code behind C#
or Call jquery from code behind

