locked
Close iframe from another page in code behind RRS feed

  • Question

  • User-610732927 posted

    I have an a web application which have a button that will open an iframe form windows.

    open.aspx is the button click

    supervisor.aspx is the page open using iframe

    if the supervisor is true, how can I automatically closed the iframe? for now I use a button click to close and I want to avoid less clicking.


    Thanks in advance

    //the open.aspx

    <div style="vertical-align: middle; text-align: center; left: 500px; width: 122px; ; top: 560px; height: 50px; z-index: 126; right: 889px; font-size: 50pt; font-family: Calibri; font-weight: bold;" id="uncheckbutton"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:Button ID="Button1" runat="server" Text="UNCHECK" /> //this is the onclick button to open the iframe <cc1:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panl1" TargetControlID="Button1" CancelControlID="Button2" BackgroundCssClass="Background"> </cc1:ModalPopupExtender> <asp:Panel ID="Panl1" runat="server" CssClass="Popup" align="center" style = "display:none"> <iframe style=" width:400px; height: 150px;" id="irm1" src="Uncheck popup.aspx" runat="server"> </iframe> <asp:button Top="100px" id="button2" runat="server" text="CLOSE" />




    //and this is the supervisor.aspx(the iframe)

    <asp:TextBox ID="inputid" runat="server" Font-Size="14px" ></asp:TextBox> <asp:Button ID="Button3" runat="server" Text="Uncheck" OnClick="btnCheck_Click" />
    if the user enter the correct username, i want the iframe to automatically close.


    //this is my supervisor.aspx.cs


    protected void btnCheck_Click(object sender,EventArgs e) { string uncheck = inputid.Text; bool supervisor = Cls.GetUncheckSupervisor(uncheck); if (supervisor==true) { this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "window.close()", .true); } else { Show("Wrong ID!"); }
    Thursday, December 5, 2019 6:22 AM

Answers

  • User665608656 posted

    Hi Maya,

    According to your description, I suggest that you can create a js method on the iframe page, call the parent layer of the iframe page, then hide the ModalPopupExtender control and panel control.

    Here is the code :

    iframe page cs:

     protected void btnCheck_Click(object sender,EventArgs e)
            { 
                string uncheck = inputid.Text;                                                                        
               
                bool supervisor = Cls.GetUncheckSupervisor(uncheck);
               
                if (supervisor==true)
                {
                     Page.ClientScript.RegisterStartupScript(this.GetType(), "Hide", "HideIframe()", true); 
                }
                else
                {
                   
    
                    Show("Wrong ID!");
    
                }
    }

    iframe page js:

        <script src="../Scripts/jquery-3.0.0.min.js"></script>
        <script type="text/javascript">
            function HideIframe() {
                $('[id*=mp1]', window.parent.document).hide();
                $('[id*=Panl1]', window.parent.document).hide(); 
            }
        </script>
    

    Here is the result of this work demo :

    Best Regards,

    YongQing.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 5, 2019 9:45 AM

All replies

  • User665608656 posted

    Hi Maya,

    According to your description, I suggest that you can create a js method on the iframe page, call the parent layer of the iframe page, then hide the ModalPopupExtender control and panel control.

    Here is the code :

    iframe page cs:

     protected void btnCheck_Click(object sender,EventArgs e)
            { 
                string uncheck = inputid.Text;                                                                        
               
                bool supervisor = Cls.GetUncheckSupervisor(uncheck);
               
                if (supervisor==true)
                {
                     Page.ClientScript.RegisterStartupScript(this.GetType(), "Hide", "HideIframe()", true); 
                }
                else
                {
                   
    
                    Show("Wrong ID!");
    
                }
    }

    iframe page js:

        <script src="../Scripts/jquery-3.0.0.min.js"></script>
        <script type="text/javascript">
            function HideIframe() {
                $('[id*=mp1]', window.parent.document).hide();
                $('[id*=Panl1]', window.parent.document).hide(); 
            }
        </script>
    

    Here is the result of this work demo :

    Best Regards,

    YongQing.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 5, 2019 9:45 AM
  • User-610732927 posted

    Thank you so much !!

    Friday, December 6, 2019 1:01 AM