Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Returning a value from a popup window

Returning a value from a popup window

Scheduled Pinned Locked Moved ASP.NET
helpquestion
10 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gretna
    wrote on last edited by
    #1

    Hi I have a calendar control appearing in a pop up window and what I would like is for the user to select a data from the calendar and it is returned to the page from which the calendar popup was opened. What would be the best way at doing this as I have found some techniques but neither have the knowledge or they don't seem to work. Any help is appreciated :)

    "When will I learn? The answers to life's problems aren't at the bottom of a bottle. They're on TV" - Homer Simpson

    A 1 Reply Last reply
    0
    • G Gretna

      Hi I have a calendar control appearing in a pop up window and what I would like is for the user to select a data from the calendar and it is returned to the page from which the calendar popup was opened. What would be the best way at doing this as I have found some techniques but neither have the knowledge or they don't seem to work. Any help is appreciated :)

      "When will I learn? The answers to life's problems aren't at the bottom of a bottle. They're on TV" - Homer Simpson

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      you have to do it using java script. window.opener.document.getElementById(window.opener.ParentControlID).value = CalendarVal.value; take Calendar value in a client side variable CalendarVal and ParentControlID is the ID of your parent window that where you want to display. Hope this will resolve your problem !!!

      cheers, Abhijit

      G 3 Replies Last reply
      0
      • A Abhijit Jana

        you have to do it using java script. window.opener.document.getElementById(window.opener.ParentControlID).value = CalendarVal.value; take Calendar value in a client side variable CalendarVal and ParentControlID is the ID of your parent window that where you want to display. Hope this will resolve your problem !!!

        cheers, Abhijit

        G Offline
        G Offline
        Gretna
        wrote on last edited by
        #3

        Hmm I have tried to implement this way but am not too sure where to start as I'm not a big javascript person. Do I need to add it to a function and then call the function from the calendar change event.

        "When will I learn? The answers to life's problems aren't at the bottom of a bottle. They're on TV" - Homer Simpson

        1 Reply Last reply
        0
        • A Abhijit Jana

          you have to do it using java script. window.opener.document.getElementById(window.opener.ParentControlID).value = CalendarVal.value; take Calendar value in a client side variable CalendarVal and ParentControlID is the ID of your parent window that where you want to display. Hope this will resolve your problem !!!

          cheers, Abhijit

          G Offline
          G Offline
          Gretna
          wrote on last edited by
          #4

          Since posting that I have since got it to work. Thank you for the help. :)

          "When will I learn? The answers to life's problems aren't at the bottom of a bottle. They're on TV" - Homer Simpson

          1 Reply Last reply
          0
          • A Abhijit Jana

            you have to do it using java script. window.opener.document.getElementById(window.opener.ParentControlID).value = CalendarVal.value; take Calendar value in a client side variable CalendarVal and ParentControlID is the ID of your parent window that where you want to display. Hope this will resolve your problem !!!

            cheers, Abhijit

            G Offline
            G Offline
            Gretna
            wrote on last edited by
            #5

            Ok this is annoying I have it working in vb.net but not working in c# i have gone through and made sure that it is putting the name of the text box of where the value is to go in the correct palce and it all seems to be fine, but when the user selects a date it closes the calendar but doesn't put the value in the text box. protected void Change_Date(object sender, System.EventArgs e) { string strScript = "window.opener.document.forms(0)." + control.Value + ".Text = '"; strScript += calDate.SelectedDate.ToString("MM/dd/yyyy"); strScript += "';self.close()"; strScript += "</" + "script>"; RegisterClientScriptBlock("anything", strScript); } "When will I learn? The answers to life's problems aren't at the bottom of a bottle. They're on TV" - Homer Simpson</x-turndown>

            A 1 Reply Last reply
            0
            • G Gretna

              Ok this is annoying I have it working in vb.net but not working in c# i have gone through and made sure that it is putting the name of the text box of where the value is to go in the correct palce and it all seems to be fine, but when the user selects a date it closes the calendar but doesn't put the value in the text box. protected void Change_Date(object sender, System.EventArgs e) { string strScript = "window.opener.document.forms(0)." + control.Value + ".Text = '"; strScript += calDate.SelectedDate.ToString("MM/dd/yyyy"); strScript += "';self.close()"; strScript += "</" + "script>"; RegisterClientScriptBlock("anything", strScript); } "When will I learn? The answers to life's problems aren't at the bottom of a bottle. They're on TV" - Homer Simpson</x-turndown>

              A Offline
              A Offline
              Abhijit Jana
              wrote on last edited by
              #6

              are you talking about vb.net or C# ? One Tips : while adding string use StringBuilder. this is good practice and good for membory also.

              cheers, Abhijit

              G 1 Reply Last reply
              0
              • A Abhijit Jana

                are you talking about vb.net or C# ? One Tips : while adding string use StringBuilder. this is good practice and good for membory also.

                cheers, Abhijit

                G Offline
                G Offline
                Gretna
                wrote on last edited by
                #7

                I originally got it to work with vb.net following your original advise and a tutorial/example I found but am now wanting it in c# and it is set up the exact same way but doesn't want to put the value in the text box. Thanks for the tip and sorry for the confusion. :)

                "When will I learn? The answers to life's problems aren't at the bottom of a bottle. They're on TV" - Homer Simpson

                A 2 Replies Last reply
                0
                • G Gretna

                  I originally got it to work with vb.net following your original advise and a tutorial/example I found but am now wanting it in c# and it is set up the exact same way but doesn't want to put the value in the text box. Thanks for the tip and sorry for the confusion. :)

                  "When will I learn? The answers to life's problems aren't at the bottom of a bottle. They're on TV" - Homer Simpson

                  A Offline
                  A Offline
                  Abhijit Jana
                  wrote on last edited by
                  #8

                  This is the code for main Page //This is Textbox where i have display the date from popuo myID= "<%=txtCal.ClientID%>"; function Button1_onclick() { //open popup page window.open("default2.aspx","test",'left=100,top=100,width=200,height=200'); } Code in Popup window **Server Side (code behiend)**

                  protected void Calendar1_SelectionChanged(object sender, EventArgs e)
                      {
                          string  dt = Calendar1.SelectedDate.ToShortDateString();
                          Page.ClientScript.RegisterStartupScript(this.GetType(), this.ClientID, "updateParent('" + dt + "');", true);
                  
                      }
                  

                  **Client Side** function updateParent() { <code><b> //Tip:Accept Argument From Server Side</b></code> var argv = updateParent.arguments; window.opener.document.getElementById(window.opener.myID).value = argv[0]; self.close(); } This should run perfectly. dont forget to vote ;)

                  cheers, Abhijit

                  G 1 Reply Last reply
                  0
                  • G Gretna

                    I originally got it to work with vb.net following your original advise and a tutorial/example I found but am now wanting it in c# and it is set up the exact same way but doesn't want to put the value in the text box. Thanks for the tip and sorry for the confusion. :)

                    "When will I learn? The answers to life's problems aren't at the bottom of a bottle. They're on TV" - Homer Simpson

                    A Offline
                    A Offline
                    Abhijit Jana
                    wrote on last edited by
                    #9

                    This is the code for main Page

                    //This is Textbox where i have display the date from popuo
                     myID= "&lt;%=txtCal.ClientID%&gt;";
                    
                    function Button1_onclick() {
                    //open popup page 
                    window.open("default2.aspx","test",'left=100,top=100,width=200,height=200');
                    }
                    

                    Code in Popup window **Server Side (code behiend)**

                    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
                        {
                            string  dt = Calendar1.SelectedDate.ToShortDateString();
                            Page.ClientScript.RegisterStartupScript(this.GetType(), this.ClientID, "updateParent('" + dt + "');", true);
                    
                        }
                    

                    **Client Side**

                     function updateParent()
                       {
                       //Tip:Accept Argument From Server Side   
                      var argv = updateParent.arguments;
                    window.opener.document.getElementById(window.opener.myID).value = argv[0];
                    self.close();
                    
                       }
                    

                    This should run perfectly. dont forget to vote ;)

                    cheers, Abhijit

                    1 Reply Last reply
                    0
                    • A Abhijit Jana

                      This is the code for main Page //This is Textbox where i have display the date from popuo myID= "<%=txtCal.ClientID%>"; function Button1_onclick() { //open popup page window.open("default2.aspx","test",'left=100,top=100,width=200,height=200'); } Code in Popup window **Server Side (code behiend)**

                      protected void Calendar1_SelectionChanged(object sender, EventArgs e)
                          {
                              string  dt = Calendar1.SelectedDate.ToShortDateString();
                              Page.ClientScript.RegisterStartupScript(this.GetType(), this.ClientID, "updateParent('" + dt + "');", true);
                      
                          }
                      

                      **Client Side** function updateParent() { <code><b> //Tip:Accept Argument From Server Side</b></code> var argv = updateParent.arguments; window.opener.document.getElementById(window.opener.myID).value = argv[0]; self.close(); } This should run perfectly. dont forget to vote ;)

                      cheers, Abhijit

                      G Offline
                      G Offline
                      Gretna
                      wrote on last edited by
                      #10

                      Thank you for sticking with me on this one. After a long day at work yesterday taring my hair out. I have gone through your sloution and got it to work. Thank you. :)

                      "When will I learn? The answers to life's problems aren't at the bottom of a bottle. They're on TV" - Homer Simpson

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups