How to pass value from child window to parent window without refreshing the page using MasterPage


Parent Window (1.aspx)

      <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
         <script type ="text/javascript">
            function popup() {
                window.open('2.aspx', '', "height=500, width=500,resizable=no, toolbar =no");
            }
        </script>
     </asp:Content>
     <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
         Text Box1:&nbsp;<asp:TextBox ID="txt1" runat="server" Width="293px">
        </asp:TextBox><br /><asp:Button ID="Button1" runat="server" Text="Button" />
    </asp:Content>

   protected void Page_Load(object sender, EventArgs e)
   {
        Button1.Attributes.Add("onclick", "popup();");
   }
  

Child Window (2.aspx)

      <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
         <script type ="text/javascript">
            function passvalue() {
                window.opener.document.getElementById("ctl00_ContentPlaceHolder1_txt1").value = document.getElementById("<%=txt2.ClientID%>").value;
                self.close();
            }
        </script>
     </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        Text Box2:&nbsp;<asp:TextBox ID="txt2" runat="server" Width="293px">
        </asp:TextBox><br /><asp:Button ID="Button1" runat="server" Text="Button" />
    </asp:Content>

    protected void Page_Load(object sender, EventArgs e)
    {
        Button1.Attributes.Add("onclick", "passvalue();");
    }
  
Published Sunday, May 16, 2010 2:50 PM by Suthish Nair
Filed under: , , ,

Comments

# re: How to pass value from child window to parent window without refreshing the page using MasterPage

Monday, June 14, 2010 3:21 AM by vidit tyagi

It help me lot.

thank u very much

# re: How to pass value from child window to parent window without refreshing the page using MasterPage

Friday, July 09, 2010 12:20 AM by Nezam

Mama it work :) Thank you...

Need some more help if u come online try to mail me...

i need help sorry to disturb

# re: How to pass value from child window to parent window without refreshing the page using MasterPage

Wednesday, August 24, 2011 10:11 AM by Rami

Hi,

I am not able to pass the value from my child form to parent form.

This is my parent form (Scheduler.aspx)

<asp:UpdatePanel ID="UpdatePanel1" runat="server">

               <ContentTemplate>

<dx:ASPxTextBox ID="ASPxpatienttb" runat="server" Width="170px"></dx:ASPxTextBox>

                <dx:ASPxButton ID="ASPxFindPatient_btn" runat="server" Text="Find Patient"

                      Height="20px" Width="169px" onclick="ASPxFindPatient_btn_Click">

                    <ClientSideEvents Click="function(s, e) {

                    window.open('FindPatient.aspx', '', &quot;height=500, width=700,resizable=no, toolbar =no&quot;);

                     }" />

</ContentTemplate>

           </asp:UpdatePanel>

My childe form(findpatient.aspx)

<script type ="text/javascript">

       function passvalue(val) {

           alert(val);

                 window.opener.document.getElementById("ctl00_ContentPlaceHolder1_ASPxpatienttb").value = val;

         self.close();

       }

   </script>

I am getting the alert(val) correctly. But I am not able to pass it to my parent textboxID..

what is wrong in my code?

Any idea?

# re: How to pass value from child window to parent window without refreshing the page using MasterPage

Thursday, October 27, 2011 3:43 AM by mohammed sami

thanks it work for me

# re: How to pass value from child window to parent window without refreshing the page using MasterPage

Wednesday, November 09, 2011 3:42 AM by milton.fernando

When adding special characters to the passed value, the javascript throws an error is there any other way we can pass value from child to parent window?

Leave a Comment

(required) 
(required) 
(optional)
(required)