Workaround for Response.Redirect

This is a workaround to do a redirect while using ASP.NET AJAX Framework. The traditional Response.Redirect method can not be used since it is not compatible with the .NET AJAX framework.

StringBuilder sb = new StringBuilder();
sb.Append("<script language=\"javascript\">\n");
sb.Append("function Redirect()\n");
sb.Append("{\n");
sb.Append("     window.parent.location.href = \"" + ResolveUrl(myURL) + "\";\n");
sb.Append("}\n");
sb.Append("</script>\n");

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Redirect", sb.ToString());
myBtn.Attributes.Add("onclick", "return Redirect();");
If you liked this post, 🗞 subscribe to my newsletter and follow me on 𝕏!