Pass Paramters from Popup to page
-
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
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"
-
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"
-
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
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) -
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)