Pass parent value to pop-up...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dorandoran
    New Member
    • Feb 2007
    • 145

    Pass parent value to pop-up...

    1. This works great.
    Code:
       <a href="javascript:void(0)" onclick="window.open('adddept.aspx','welcome','width=400,height=250')">Add a Department </a>
    2. I am trying to Pass a value "txtParentI D" to pop up window "txtChildID "

    I found a java for the second item. but how do I get # 1 to execute the java function after it opens up pop up window.


    Last edited by Frinavale; Mar 31 '09, 01:58 PM. Reason: Added [code] tags. Please post code in [code] [/code] tags.
  • dorandoran
    New Member
    • Feb 2007
    • 145

    #2
    Code:
    <a href="javascript:void(0)" onclick="window.open('Assign_Dept.aspx?value = " + txtParent.Text + " ','welcome','width=400,height=250')">
                                                Assign Dept test</a>
    theParent.Text is in red and it tells me is not a valid attribute of a. what would be the right syntax?
    Last edited by Frinavale; Mar 31 '09, 01:58 PM. Reason: Added [code] tags. Please post code in [code] [/code] tags.

    Comment

    • gits
      Recognized Expert Moderator Expert
      • May 2007
      • 5388

      #3
      the first param in the window.open() method should look like this:

      Code:
      'Assign_Dept.aspx?value = \"' + txtParent.Text + '\"'
      kind regards

      Comment

      • dorandoran
        New Member
        • Feb 2007
        • 145

        #4
        Hi gits, I tried your suggession but still nothing happens when I click on the button.

        This is my textbox
        Code:
        <asp:TextBox ID="txtParent" runat="server" ></asp:TextBox></td>
        Here is the href
        Code:
        <a href="javascript:void(0)" onclick="window.open('Assign_Dept.aspx?value = \"' + txtParent.Text + '\"','welcome','width=400,height=250')">
                                                    Assign Dept test</a>
        Any help will be truly appreciated as I spend more than 8 hours on this.
        Last edited by Frinavale; Mar 31 '09, 01:58 PM. Reason: Added [code] tags. Please post code in [code] [/code] tags.

        Comment

        • gits
          Recognized Expert Moderator Expert
          • May 2007
          • 5388

          #5
          when you call:

          Code:
          alert('Assign_Dept.aspx?value = \"' + txtParent.Text + '\"');
          in your onclick handler, does the alert show you the correct url?

          kind regards

          Comment

          • dorandoran
            New Member
            • Feb 2007
            • 145

            #6
            This works but I need to pass value.
            Code:
            <a href="javascript:void(0)" onclick="window.open('Assign_Dept.aspx','welcome','width=400,height=250')">Assign Dept.&nbsp;</a>
            Last edited by Frinavale; Mar 31 '09, 01:57 PM. Reason: Added [code] tags. Please post code in [code] [/code] tags.

            Comment

            • gits
              Recognized Expert Moderator Expert
              • May 2007
              • 5388

              #7
              did the alert work?

              kind regards

              Comment

              • dorandoran
                New Member
                • Feb 2007
                • 145

                #8
                Alert works on the first href but does not work on the 2nd href.

                Code:
                <a href="javascript:void(0)" onclick="alert('Assign_Dept.aspx','welcome','width=400,height=250')">Assign Dept.&nbsp;</a>
                <br /> 
                <br />
                 <a href="javascript:void(0)" onclick="window.open('Assign_Dept.aspx?value = \"' + txtParent.Text + '\"','welcome','width=400,height=250')">
                                                            Assign Dept test</a>
                Last edited by Frinavale; Mar 31 '09, 01:57 PM. Reason: Added [code] tags. Please post code in [code] [/code] tags.

                Comment

                • gits
                  Recognized Expert Moderator Expert
                  • May 2007
                  • 5388

                  #9
                  try the following ... we separate the build of the url here:

                  Code:
                  onclick="var url = 'Assign_Dept.aspx?value = \"' + txtParent.Text + '\"';  window.open(url,'welcome','width=400,height=250')"
                  this should work otherwise please tell what value the variable has ...

                  kind regards

                  Comment

                  • dorandoran
                    New Member
                    • Feb 2007
                    • 145

                    #10
                    Code:
                    <a href="javascript:void(0)" onclick="var url = 'Assign_Dept.aspx?value = \"' + txtParent.Text + '\"';  window.open(url,'welcome','width=400,height=250')" >
                                                            Assign Dept </a>
                    Not working. Nothing happens.
                    txtParent.text has integer (string to be correct) in it. I am populating this text box when I select a row from a gridview. and I can see it's been populated after i select a row.
                    Code:
                        protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
                        {
                                    txtParent.Text = GridView2.SelectedValue.ToString();
                        }
                    Last edited by Frinavale; Mar 31 '09, 01:57 PM. Reason: Added [code] tags. Please post code in [code] [/code] tags.

                    Comment

                    • gits
                      Recognized Expert Moderator Expert
                      • May 2007
                      • 5388

                      #11
                      ahhhrg .... tried it myself now and we get an unterminatetd string-literal at the first double quote, just try it without concatenating the double quotes:

                      Code:
                      var url = 'Assign_Dept.aspx?value=' + txtParent.Text;
                      as far as i'm aware you don't need them, and in case you do we could try the encodeURICompon ent() method, since it seems that in the onclick the escape of the double quotes didn't work. you could even write a function in an extra script-block and call the function in your onclick, that would circumvent this silly problem.

                      kind regards

                      Comment

                      • dorandoran
                        New Member
                        • Feb 2007
                        • 145

                        #12
                        I am going to give up after 3 day mission on this. Thanks gits for keeping up with me and helping me.

                        Comment

                        • gits
                          Recognized Expert Moderator Expert
                          • May 2007
                          • 5388

                          #13
                          the last suggestions i gave above should work ... personally i would prefer the function wrapper way. just put a function like below in a script section in the head of your page:

                          [CODE=javascript]function openMyWindow() {
                          var url = 'foo.html?value ="' + myValue + '"';

                          window.open(url , // more params here);
                          }[/CODE]
                          now in your onclick handler just call:

                          [CODE=html]onclick="openMy Window()"[/CODE]
                          it's a too small problem to just give up ;) ...

                          kind regards

                          Comment

                          • dorandoran
                            New Member
                            • Feb 2007
                            • 145

                            #14
                            gits,

                            Thanks for keeping up with me on this. I understand what you said about not giving up. Thanks for keeping me up and not give up.

                            Guess what. it FINALLY WORKED. I am posting the final code in case someone wants to implement this.

                            parent.aspx

                            1. Put this script before head (form1 is the name of my form where txtParent form is located
                            Code:
                            <script type="text/javascript" language="javascript">
                            function openMyWindow() { 
                                var myValue = form1.txtParent1.value
                                var url = 'PopUp.aspx?value=' + myValue + ''; 
                              
                                window.open(url);   // more params here, like width, height, etc.
                            } 
                            </script>
                            2. This is my Click Text (you can use button)
                            Code:
                                <a href="javascript:void(0)" onclick="openMyWindow()">Open Pop - Bytes</a>
                            3. popup.aspx , put this code on the pageload of popup.aspx
                            Code:
                                        string strP = Request["value"].ToString();
                                        txtPopup2.Text = strP;
                            ALL THE THANKS TO gits because he has lots of patience and never gave up on me. Thank you gits.
                            Last edited by Frinavale; Mar 31 '09, 01:56 PM. Reason: Added [code] tags. Please post code in [code] [/code] tags.

                            Comment

                            • gits
                              Recognized Expert Moderator Expert
                              • May 2007
                              • 5388

                              #15
                              glad to hear you got it working ;) ... in case you would have more questions just post back to the forum ;)

                              kind regards,
                              gits

                              Comment

                              Working...