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. General Programming
  3. C#
  4. Pass Paramters from Popup to page

Pass Paramters from Popup to page

Scheduled Pinned Locked Moved C#
question
5 Posts 3 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.
  • A Offline
    A Offline
    Agweet
    wrote on last edited by
    #1

    Hi All...can any1 assist, im trying to pass values from a datagrid in a popup window to my main page...how can i do this?

    living life on the flip side

    A D 2 Replies Last reply
    0
    • A Agweet

      Hi All...can any1 assist, im trying to pass values from a datagrid in a popup window to my main page...how can i do this?

      living life on the flip side

      A Offline
      A Offline
      Alaric_
      wrote on last edited by
      #2

      If you are truly in a "Popup" (i.e. a modal dialog box), simply overload the ShowDialog method in your "popup" form to call the base implementation of ShowDialog and return the value that you want to have passed back.

      private List list;
      .
      .
      .
      protected void btnSubmit_Click(object sender, EventArgs e)
      {
      list = DataGrid.DataSource; //I pulled this property off the top of my head. You'll have to play
      //with it
      this.close();
      }

      public List ShowDialog()
      {
      base.ShowDialog();
      return list;
      }

      Have the "OK" button (or whatever flow control you have in place) set the variable you wish to return and close the form.

      "I need build Skynet. Plz send code"

      A 1 Reply Last reply
      0
      • A Alaric_

        If you are truly in a "Popup" (i.e. a modal dialog box), simply overload the ShowDialog method in your "popup" form to call the base implementation of ShowDialog and return the value that you want to have passed back.

        private List list;
        .
        .
        .
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
        list = DataGrid.DataSource; //I pulled this property off the top of my head. You'll have to play
        //with it
        this.close();
        }

        public List ShowDialog()
        {
        base.ShowDialog();
        return list;
        }

        Have the "OK" button (or whatever flow control you have in place) set the variable you wish to return and close the form.

        "I need build Skynet. Plz send code"

        A Offline
        A Offline
        Agweet
        wrote on last edited by
        #3

        Hi Alaric...im actually using window.open and inside the window is my page...i want the datagrid values to be sent from this page to my main form

        living life on the flip side

        1 Reply Last reply
        0
        • A Agweet

          Hi All...can any1 assist, im trying to pass values from a datagrid in a popup window to my main page...how can i do this?

          living life on the flip side

          D Offline
          D Offline
          DaveyM69
          wrote on last edited by
          #4

          Use delegates. There's plenty of examples here and on the internet. Here's a very simple example to get you started. Create a Windows Forms Application and call it DelegateExample. You'll already have Form1. Add another form and call it Form2 then add a TextBox to it called textBox1. Change all the code in Form1.cs to this:

          using System;
          using System.Windows.Forms;

          namespace DelegateExample
          {
          public delegate void UpdateText(string text);

          public partial class Form1 : Form
          {
              public Form1()
              {
                  InitializeComponent();
              }
              private void Form1\_Load(object sender, EventArgs e)
              {
                  Form2 frm2 = new Form2();
                  frm2.SendText = new UpdateText(Update);
                  frm2.Show();
              }
              private void Update(string text)
              {
                  Text = text;
              }
          }
          

          }

          Change all the code in Form2.cs to this:

          using System;
          using System.Windows.Forms;

          namespace DelegateExample
          {
          public partial class Form2 : Form
          {
          public UpdateText SendText;
          public Form2()
          {
          InitializeComponent();
          }
          private void textBox1_TextChanged(object sender, EventArgs e)
          {
          SendText(textBox1.Text);
          }
          }
          }

          When you run this - type in the TextBox on Form2 and the Text in the title bar of Form1 will change as you type. Study the code so you understand what it's doing then you can use this principal in your situation with very little modification.

          Dave
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

          A 1 Reply Last reply
          0
          • D DaveyM69

            Use delegates. There's plenty of examples here and on the internet. Here's a very simple example to get you started. Create a Windows Forms Application and call it DelegateExample. You'll already have Form1. Add another form and call it Form2 then add a TextBox to it called textBox1. Change all the code in Form1.cs to this:

            using System;
            using System.Windows.Forms;

            namespace DelegateExample
            {
            public delegate void UpdateText(string text);

            public partial class Form1 : Form
            {
                public Form1()
                {
                    InitializeComponent();
                }
                private void Form1\_Load(object sender, EventArgs e)
                {
                    Form2 frm2 = new Form2();
                    frm2.SendText = new UpdateText(Update);
                    frm2.Show();
                }
                private void Update(string text)
                {
                    Text = text;
                }
            }
            

            }

            Change all the code in Form2.cs to this:

            using System;
            using System.Windows.Forms;

            namespace DelegateExample
            {
            public partial class Form2 : Form
            {
            public UpdateText SendText;
            public Form2()
            {
            InitializeComponent();
            }
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
            SendText(textBox1.Text);
            }
            }
            }

            When you run this - type in the TextBox on Form2 and the Text in the title bar of Form1 will change as you type. Study the code so you understand what it's doing then you can use this principal in your situation with very little modification.

            Dave
            BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

            A Offline
            A Offline
            Agweet
            wrote on last edited by
            #5

            Hi Davey...thnx for the reply,,,ill try and see what happens...thnx again

            living life on the flip side

            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