Click here to Skip to main content
15,911,890 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm working inside an iframe and when i finish my job I want to change page NOT inside iframe, but out side of this it, I want to open it in the window.
For this I use the following Sub:

VB
Public Sub ChangePage(sender As Object, e As EventArgs)
        Dim myNewAsp As New AspNetSqlProvider
        Dim dbHandler As New DBHandler
        Dim srvHandler As New ServerHandler
        Dim aspProvider As New MyAspNetSqlMembershipProvider
        Dim errAnswer As New Register
        Dim assit As New Assistance
        Dim currentUser As MembershipUser = Nothing
        Dim message As String = Nothing
        Dim msg As String = Nothing
        Try
            Dim url As String = "/Pages/Account/Login.aspx"
            Dim postWindow As Object   ' "/Pages/Account/Assistance.aspx"
            Dim startWindow As Object   ' "/Pages/Support/Asp/Help01.aspx"
            Dim urlURI As String = HttpContext.Current.Request.Url.AbsoluteUri
            Dim urlPath As String = HttpContext.Current.Request.Url.AbsolutePath
            Dim myServerName As String = Strings.Left(urlURI, urlURI.Length - urlPath.Length)
            url = myServerName + url
            startWindow = Me.GetType().FullName
            postWindow = Assistance.PageUrlType
            msg = "<script type='text/javascript'> $(document).ready(function(){  window.location.href='" + url + "';  }); </script>"
            Dim script As Type = Me.Page.GetType()  '  Assistance.PageType.BaseType
            Dim postmsg As String = "ChangePage('" & startWindow & "', '" & postWindow & "', '" & msg & "')"
            If Not Page.ClientScript.IsStartupScriptRegistered(Me.GetType(), "sendMessage") Then
                Page.ClientScript.RegisterStartupScript(script, "sendMessage", postmsg, False)
            End If

        Catch eq As SqlException
            srvHandler.ErrorAnswer = DBHandler.GetError(1, Nothing, Nothing, eq, Nothing)
            srvHandler.ErrorAnswer = srvHandler.ErrorAnswer & "\r\n Asp.SQLProvider.ResetPassword "
            ServerHandler._InnerError += srvHandler.ErrorAnswer
            Register.errorCall = True
            Return
        Catch Ex As Exception
            srvHandler.ErrorAnswer = DBHandler.GetError(3, Ex, Nothing, Nothing, Nothing)
            srvHandler.ErrorAnswer = srvHandler.ErrorAnswer & "\r\n Asp.SQLProvider.ResetPassword"
            ServerHandler._InnerError += srvHandler.ErrorAnswer
            Register.errorCall = True
            Return

        End Try
End Sub


In the Assistance.aspx I have these Properties:

And for the iFrame:

VB
Public WithEvents iFrame As System.Web.UI.HtmlControls.HtmlGenericControl


Also I use these two properties to pass the control elements in the other page:

VB
Public Shared _PageUrlType As Object
    Public Shared Property PageUrlType() As Object
        Get
            Return _PageUrlType
        End Get
        Set(value As Object)
            _PageUrlType = value
        End Set
    End Property
    Public Shared _PageType As Type
    Public Shared Property PageType() As Type
        Get
            Return _PageType
        End Get
        Set(value As Type)
            _PageType = value
        End Set
    End Property


I also use the following script in the Page inside the `iFrame`:

JavaScript
<script type="text/javascript">
     function ChangePage(startPage, sendPage, message) {
         var sPage = document.getElementById(sendPage);
         sPage.contentWindow.postMessage(message, startPage);
     }
    </script>


I also use the following script in the Page I want to change (parent Page):

JavaScript
<script type="text/javascript">
    window.addEventListener("message", receiveMessage, false);
    function receiveMessage(event) {
        event.origin !== message;
        event.source.postMessage("'" + message + "'", event.origin);
            return;
    }
</script>


what I got from the above is to have the desired page BUT inside of the frame.
The scrip in the Help01.aspx page is executed just fine. But in this window, and not in the parent one (Assistance,aspx)
As a result I can't get out of the iFrame (which is inside of a table).
Is someone to know what to do about it?
Posted
Updated 29-Jan-14 8:14am
v2

1 solution

This seems like a really bad idea. You're trying to swap out the rest of of a tree when you're sitting on one of it's branches.

I can't think of a way to make this work at all.

The only solution I can think of is to make a master page that holds a couple of frames. The page you want to swap out sits in one frame, sitting along side the other frame that hosts the page that you don't want to swap out.
 
Share this answer
 
Comments
Lefteris Gkinis 30-Jan-14 2:52am    
Well the basic idea developing this… is to open a number of pages (9) with deferent scope each other, inside of this iFrame.
The all project has only one “master” page which it work for all the pages except of the pages inside the iFrame… they are stand alone.
I’m starting from the Log In Page for someone which wants a Help to logged In.
So a number of pages open to this iFrame, from where I want to leave each time I finish what the page want me to do.
Finally your idea is to use another control to open in this table (because the iFrame lies in a table) and do my job…
Someone else (from another Blog) told me that I could use the postMessage, which is an instruction sending messages from one page to another... And in place of message I could set the redirection of the new page.
I use that but the massages never send outside of this iFrame the postMessages works but inside the iFrame.
Dave Kreskowiak 30-Jan-14 9:43am    
1 iFrame = 1 web page. In order to get 9 pages to open, you'll need 9 iFrames to put them in.

As for everything else you're saying, I have no idea.
Lefteris Gkinis 30-Jan-14 9:48am    
OK Thank you very much Dave you're very helpful... I know what you mean... and sorry for my long description of my issue

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900