Transfer Date from one page to another in aspx

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • imtmub
    New Member
    • Nov 2006
    • 112

    Transfer Date from one page to another in aspx

    I have two page one is parent and child. Parent page has text field and command button. The Link button open a child page as a popup. Child page as Text box and Button. when i click the button it will transfer child textbox data parent page text box. this is working fine when i use normal page(Not using master page on it).
    Parent page aspx:
    Code:
     
    <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"></asp:TextBox>
    <a href="#" onclick="OpenNewWindow()">Lookup</a>
     
     
    function OpenNewWindow() 
    {
    window.open('Child.aspx','MyPopUp','width=500,height=700,scrollbars=1,resizable=1');
    }
    Child.aspx:
    Code:
     
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <input id="Button2" onclick="Transfer()" type="button" value="Select" style="width: 65px" />
      
    function Transfer() 
    {
    window.opener.form1.TextBox1.value = document.getElementById("TextBox1").value; 
    window.close(); 
    }
    This code is working fine. Child page transfer the data parent.

    But i when i use master page in parent page. I can open child page using pop up. The child page not transfering the data to parent page with same code. i dont know whats went wrong. Can i anybody what i have to change. I am not getting any error and the data is not transfering

    Thanks in advance
    Last edited by DrBunchman; May 27 '08, 07:36 AM. Reason: Added code tags - note the # button
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Hi imtmub,

    If you check the source html generated by your code you'll probably find that the ID of TextBox1 has been changed to something like ctl00_Content1_ TextBox1.

    To get the actual ID you need to pass the ClientID property of your TextBox control to your popup window and use that to pass the value back. Here's an example:

    Parent:
    Code:
    window.open('Child.aspx?txt=<%=TextBox1.ClientID%>','MyPopUp','width=500,height=700,scrollbars=1,resizable=1');
    Child:
    Code:
    window.opener.form1.TextBox1.value = document.getElementById('" & Request.Querystring("txt") & "').value;
    Let me know how you get on,

    Dr B

    PS You posted this in the ASP Forum which is for Classic ASP only - I've moved it for you but please remember to post all future ASP.NET questions in the .NET Forum. Thanks.

    Comment

    • imtmub
      New Member
      • Nov 2006
      • 112

      #3
      Dr B
      First of all I have to say thanks for ur response.
      When i check the Source html genreted by my code My Textbox1 id change to "ctl00_ContentP laceHolder1_Tex tBox1"

      Then I have modified my java function according to your suggestion. Still i am facing the same problem. The Textbox is not transfering data to parent page textbox. Can u see anyother info i need to change?

      Thanks

      Comment

      • DrBunchman
        Recognized Expert Contributor
        • Jan 2008
        • 979

        #4
        Can you show me the code you're using now on each page please?

        Thanks,

        Dr B

        Comment

        • imtmub
          New Member
          • Nov 2006
          • 112

          #5
          Originally posted by DrBunchman
          Can you show me the code you're using now on each page please?

          Thanks,

          Dr B
          Parent Page:
          Code:
           
          <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"></asp:TextBox>
          <a href="#" onclick="OpenNewWindow()">Lookup</a>
          function OpenNewWindow() 
          {
           
          window.open('ChildMain.aspx?txt=<%=TextBox1.ClientID%>','MyPopUp','width=500,height=700,scrollbars=1,resizable=1');
          }
          ChildMain:
          Code:
           
          <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
          <input id="Button2" onclick="Transfer()" type="button" value="Select" style="width: 65px" />
            
          function Transfer() 
          {
          window.opener.form1.TextBox1.value = document.getElementById('" & Request.Querystring("txt") & "').value;
          window.close(); 
          }
          Thanks
          Last edited by DrBunchman; Jun 2 '08, 04:13 PM. Reason: Added code tags - Please use the # button

          Comment

          • DrBunchman
            Recognized Expert Contributor
            • Jan 2008
            • 979

            #6
            I can't see anything obvious - can you check the value that is passed in the querystring and compare it the actual ID from your mark-up. Are they the same?

            Comment

            • imtmub
              New Member
              • Nov 2006
              • 112

              #7
              Originally posted by DrBunchman
              I can't see anything obvious - can you check the value that is passed in the querystring and compare it the actual ID from your mark-up. Are they the same?
              I have checked. I m going to leave this wndow.opener.
              Do you any other method that i can post back value

              Comment

              • imtmub
                New Member
                • Nov 2006
                • 112

                #8
                Originally posted by imtmub
                I have checked. I m going to leave this wndow.opener.
                Do you any other method that i can post back value
                I dont know where i m doing wrong. if ou have any demo page that will be great help

                Comment

                • imtmub
                  New Member
                  • Nov 2006
                  • 112

                  #9
                  Originally posted by imtmub
                  I dont know where i m doing wrong. if ou have any demo page that will be great help
                  Please i wana complete this form with in this week. please help me to transfer data from child page text box to parent page text box.
                  I have tried java funstion is not working out for me. If you any vb script or demo page that will be great help.

                  Comment

                  • imtmub
                    New Member
                    • Nov 2006
                    • 112

                    #10
                    Originally posted by imtmub
                    Please i wana complete this form with in this week. please help me to transfer data from child page text box to parent page text box.
                    I have tried java funstion is not working out for me. If you any vb script or demo page that will be great help.
                    I m waiting answer. Please help me out

                    Comment

                    • kunal pawar
                      Contributor
                      • Oct 2007
                      • 297

                      #11
                      Please do not use form1 in Transfer method

                      this may helps you

                      document.opener .document.getEl ementById("Text 1").value = document.getEle mentById("text1 ").value;




                      modify ur code and let me know updates

                      Comment

                      • imtmub
                        New Member
                        • Nov 2006
                        • 112

                        #12
                        Originally posted by kunal pawar
                        Please do not use form1 in Transfer method

                        this may helps you

                        document.opener .document.getEl ementById("Text 1").value = document.getEle mentById("text1 ").value;




                        modify ur code and let me know updates
                        I have modified as per ur suggestion. But still its same

                        Comment

                        • Frinavale
                          Recognized Expert Expert
                          • Oct 2006
                          • 9749

                          #13
                          Originally posted by imtmub
                          I have modified as per ur suggestion. But still its same
                          I'm not the greatest with JavaScript but I'm almost 100% sure that you cannot transfer data between a child and parent browser.

                          You will have to try and use the server to transfer the data.
                          The problem is that after your child window is finished, the parent one will have no idea that this has happened and the server has no way to indicate to the parent browser that there is updated data waiting for it.

                          I would suggest placing the content of your child window inside a <div> that can be positioned to display as if it were floating in front of the parent data. Remember that asp Panels are rendered as <div>'s. That way your "parent" will have access to the data in the "child"...t he only difference is that you aren't using 2 browsers.


                          -Frinny

                          Comment

                          • imtmub
                            New Member
                            • Nov 2006
                            • 112

                            #14
                            Originally posted by Frinavale
                            I'm not the greatest with JavaScript but I'm almost 100% sure that you cannot transfer data between a child and parent browser.

                            You will have to try and use the server to transfer the data.
                            The problem is that after your child window is finished, the parent one will have no idea that this has happened and the server has no way to indicate to the parent browser that there is updated data waiting for it.

                            I would suggest placing the content of your child window inside a <div> that can be positioned to display as if it were floating in front of the parent data. Remember that asp Panels are rendered as <div>'s. That way your "parent" will have access to the data in the "child"...t he only difference is that you aren't using 2 browsers.


                            -Frinny
                            I have place my function inside <div></div> but still its acting same. I m not getting what i want.

                            Comment

                            • kunal pawar
                              Contributor
                              • Oct 2007
                              • 297

                              #15
                              can u check

                              Code:
                               
                              document.opener.document.getElementById("Text1").value = document.getElementById("text1").value;
                                
                              alert("Val 1 : " + document.getElementById("text1").value); 
                              alert("Val 2 : " + document.opener.document.getElementById("Text1").value);
                              Last edited by DrBunchman; Jun 2 '08, 10:48 AM. Reason: Added code tags - Please use the # button

                              Comment

                              Working...