Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access a parent element from iframe using c#?

Tags:

c#

asp.net

iframe

I am working on a website in asp.Net, and i am using iframe to load a separate page. The separate page named Districting.aspx, includes an asp button, which onClick(), calls a function in c#, named DoneClicked(). This is the asp button control:

<asp:Button ID="LinkButtonDone" CssClass="button button-yellow" runat="server" OnClick="DoneClicked" Text="Done" />

In code behind, the DoneClicked function:

protected void Doneclicked(object sender, EventArgs e)
    {
        // Some code here
        // Calling a function from Default page
    }

What I need to do is at the end of DoneClicked function, a function from the Default.aspx page must be called.

So how can I access a function from Default.aspx.cs in the iframe page code behind?

Thanks:)

like image 852
Hanady Avatar asked Nov 21 '12 11:11

Hanady


2 Answers

Try Below It Worked for me

In Code Behind

protected void Doneclicked(object sender, EventArgs e)
    {
        ScriptManager.RegisterStartupScript(this, this.GetType(), "scriptid", "window.parent.location.href='ParentPageName.aspx';", true);  
 }
like image 198
Divya Rana Avatar answered Sep 29 '22 03:09

Divya Rana


You can't access it directly (at least not in an advisable fashion).

You should abstract out the common code from Default.aspx into a class somewhere that can be used by both pages.

like image 45
Justin Harvey Avatar answered Sep 29 '22 03:09

Justin Harvey