I know this isn't possible, but what is the best alternative for wanting to do Response.Redirect
from an iFrame, to redirect the parent page?
Redirect the page containing your iframe embed Modern browsers will prevent an iframe from changing the location of its parent page for security reasons. Your iframe embed code and JavaScript code will need to be modified to allow this behavior.
Response. Redirect sends an HTTP request to the browser, then the browser sends that request to the web server, then the web server delivers a response to the web browser. For example, suppose you are on the web page "UserRegister. aspx" page and it has a button that redirects you to the "UserDetail.
You can set sandbox="" , which prevents the iframe from redirecting. That being said it won't redirect the iframe either. You will lose the click essentially.
You can not do this using ASP.NET. ASP.NET on server side can redirect incoming request and can't know about a parent frame.
But if you want to redirect parent frame on some server side condition you can call JavaScript from server like this:
protected void Page_Load(object sender, EventArgs e) {
ClientScriptManager.RegisterClientScriptBlock(this.GetType(),
"RedirectScript", "window.parent.location = 'http://yoursite.com'", true);
}
And of course you can use simple JavaScript window.parent.location = 'http://yoursite.com' on client side.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With