locked
Unable access parentwindow textbox from modalpopup RRS feed

  • Question

  • User-2041614075 posted

    Hi, 

       i am unable to access parentwindow textbox from the modalpopup.  Can you please guide me.

    Wednesday, February 13, 2019 7:44 PM

All replies

  • User-1174608757 posted

    Hi praveen3345,

    According to your description , I guess you are using  in your popup window and you want to access textbox in parent window.I suggest you to use 

    window.parent.document.getElementById()

    to get element of parent window in the iframe page. Here is a demo , I hope it could help you.

    Parentpage.aspx:

    <head runat="server">
        <title></title>
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
        <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
    
    <script>
        $(function () {
            $("#But1").click(function () {
    
                $("#exampleModal1").modal("show") 
            })
    
        })
        
    </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div class="modal fade" id="exampleModal1" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog" role="document">
           <div class="modal-content">
                  <div class="modal-body" style="text-align:center">
                      <iframe name="iframe1"  src="iframe.aspx"></iframe>  
                  </div>
                    
        </div>
      </div>
    </div>
            <asp:TextBox ID="TextBox1" runat="server" Text="Text in parent window"></asp:TextBox> <%--this is  textbox in parent page --%> 
            <input id="But1" type="button" value="show popup window" />
        </form>
    </body>
    </html>
    

    iframe.aspx:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="../Scripts/jquery-3.3.1.js"></script>
        <script>
            $(function ()
            {
                var a = window.parent.document.getElementById("TextBox1").value;<%--get the value of textbox in parent window --%> 
                $("#Button1").click(function ()
                {
                    alert(a); 
    
    
                })
    
    
    
            })
                
               
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <h1>This is a iframe window</h1>
                <input id="Button1" type="button" value="button" />
            </div>
        </form>
    </body>
    </html>
    

    it shows as below:

    Best Regards

    Wei Zhang

    Thursday, February 14, 2019 3:19 AM
  • User438705957 posted

    How do you make those animations Wei. They come in very handy.

    Tuesday, February 26, 2019 1:39 AM