Pages

Subscribe:

Ads 468x60px

Saturday, March 10, 2012

how to redirect from IFrame in asp.net using c#

In this web programming tutorial we will learn that how we can perform redirection from IFrame to next page instead within IFrame in asp.net using c#. One of my friends has got a requirement; he has a webpage that contains the form containing username and password textboxes, one asp:button to validate and verify the username and password, after performing validation, it redirects the registered user to another page but problem was that the next page was being opened inside the iframe rather than in parent window because the webpage that containing the form was also in iframe. It became quite headache for us to solve the problem but finally we did it.
protected void btn_Submit_Click(object sender, EventArgs e)  
{  
//your code to verify username/password will come here  
ScriptManager.RegisterStartupScript(this, this.GetType(), "redirect", "if(top!=self) {top.location.href = 'next-page.aspx';}", true);  
}  
Note:- In case if this code is not working properly in IE9 then you have to give the absolute path of targeting webpage such as
if(top!=self) {top.location.href = 'https://www.yourwebsite.com/next-page.aspx';}", true);  
Using the server side onClick event of asp:button, we are redirecting user to another page but now page will not be open inside the iframe because the javascript code that we have written in the server side onClick event of asp:button will take care that user must be redirected to next page within parent window rather than IFrame.

No comments:

Post a Comment