Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 17th, 2009, 06:10 AM
Friend of Wrox
Points: 686, Level: 9
Points: 686, Level: 9 Points: 686, Level: 9 Points: 686, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Kolkata, West Bengal, India.
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sending values from Popup to Parent window

Hi All !!

It seems everyone in this forum works on Web Applications and I haven't found anyone helping out with Windows Applications . That's a pity.

I am working on a Windows Application where I have a Parent Windows Form which opens a Popup Window with a button click. In the Popup window there is a Listbox where I can choose a value & click OK.

With the OK button click event I have written code which picks up values from database depending on the value selected from the Listbox. Now after closing the Popup window with the OK button the values picked from the databases have to populate the Texbox controls of the Parent Windows Form

The code I have written works but with a Hitch. Every time I close the Popup window a new Parent Window is opened with the Textbox Controls populated and the original Parent Window remains open without any controls populated.

I am putting the codes from both the forms here. Kindly let know where I might have gone wrong. Remember there is no problem in retrieving values from Popup.

Code for Parent Window :
Code:
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Web;
namespace QuizPro
{
    public partial class frmQuizName : Form
    {
        public frmQuizName()
        {
            InitializeComponent();
        }
        public frmQuizName(string strQid, string strQName)
        {
            InitializeComponent();
            this.txbQuizid.Text = strQid;
            this.txtQuizName.Text = strQName;
        }
        private void frmQuizName_Load(object sender, EventArgs e)
        {
            btnDelete.Visible = false;
        }
        private void btnSaveEdit_Click(object sender, EventArgs e)
        {
            if (txbQuizid.Text == "")
            {
                btnSaveEdit.Text = "&Save";
                InsertRecords();
                Refresh();
            }
            else
            {
                btnSaveEdit.Text = "&Edit";
                EditRecords();
            }
        }
        private void InsertRecords()
        {
            
            try
            {
                string newDt = Convert.ToString(DateTime.Now.Day) +"/" + Convert.ToString(DateTime.Now.Month) + "/" + Convert.ToString(DateTime.Now.Year);
                OleDbConnection conn = TheConnection();
                OleDbCommand cmd = new OleDbCommand();
                cmd.Connection = conn;
                string qid = getQuizID();
                cmd.CommandText = "Insert into Quiz_Master(QuizID,Quiz_Name,CreatDt) values('" + qid + "','" + txtQuizName.Text + "','" + newDt + "')";
                int recCount = cmd.ExecuteNonQuery();
                MessageBox.Show("Record Inserted Successfully");
                conn.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            
        }
        private void EditRecords()
        {
        }
        private string getQuizID()
        {
            string QuzId = string.Empty;
            OleDbConnection newcon = TheConnection();
            OleDbCommand newcmd = new OleDbCommand();
            newcmd.Connection = newcon;
            OleDbDataAdapter dadpter = new OleDbDataAdapter("Select Count(*) as RecCount from Quiz_Master",newcon);
            DataSet ds = new DataSet();
            dadpter.Fill(ds, "Quiz_Master");
            DataTable dt = ds.Tables[0];
            if (dt.Rows[0]["RecCount"].ToString() != string.Empty)
            {
                if (dt.Rows[0]["RecCount"].ToString().Length == 1)
                {
                    QuzId = "Q" + "000" + Convert.ToString(Convert.ToInt32(Convert.ToInt32(Convert.ToString(dt.Rows[0]["RecCount"])) + 1));
                }
                else if (dt.Rows[0]["RecCount"].ToString().Length == 2)
                {
                    QuzId = "Q" + "00" + Convert.ToString(Convert.ToInt32(Convert.ToInt32(Convert.ToString(dt.Rows[0]["RecCount"])) + 1));
                }
                else if (dt.Rows[0]["RecCount"].ToString().Length == 3)
                {
                    QuzId = "Q" + "0" + Convert.ToString(Convert.ToInt32(Convert.ToInt32(Convert.ToString(dt.Rows[0]["RecCount"])) + 1));
                }
                else if (dt.Rows[0]["RecCount"].ToString().Length == 4)
                {
                    QuzId = "Q" + Convert.ToString(Convert.ToInt32(Convert.ToInt32(Convert.ToString(dt.Rows[0]["RecCount"])) + 1));
                }
            }
            else
            {
                QuzId = "Q" + "0001";
            }
            return QuzId;
        }
        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }
        private void btnShowQuiz_Click(object sender, EventArgs e)
        {
            ShowQuiz frmchild = new ShowQuiz();
            frmchild.Width = 480;
            frmchild.Height = 290;
            frmchild.Top = 65;
            frmchild.Left = 350;
            frmchild.Show();
        }
        private OleDbConnection TheConnection()
        {
            OleDbConnection conn = new OleDbConnection();
            string Connstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\Quiz Software\\QuizDB.mdb";
            conn.ConnectionString = Connstring;
            conn.Open();
            return conn;
        }
    }
}


Highlighted code shows the relevant code area.

Popup page Code:
Code:
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace QuizPro
{
    public partial class ShowQuiz : Form
    {
        public ShowQuiz()
        {
            InitializeComponent();
        }
        private void ShowQuiz_Load(object sender, EventArgs e)
        {
            try
            {
                DateTime newDt = DateTime.Now;
                OleDbConnection newcon = TheConnection();
                OleDbCommand cmd = new OleDbCommand();
                cmd.Connection = newcon;
                cmd.CommandText = "Select QuizID,Quiz_Name from Quiz_Master order by QuizID";
                OleDbDataReader dr = cmd.ExecuteReader();
                lstQuizName.Items.Clear();
                lstQuizName.BeginUpdate();
                while (dr.Read())
                {
                    lstQuizName.Items.Add(dr.GetString(1));
                }
                lstQuizName.EndUpdate();
                dr.Close();
                newcon.Close();
            }
            catch
            {
            }
        }
        private OleDbConnection TheConnection()
        {
            OleDbConnection conn = new OleDbConnection();
            string Connstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\Quiz Software\\QuizDB.mdb";
            conn.ConnectionString = Connstring;
            conn.Open();
            return conn;
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            string aa="";
            string selctdVal = lstQuizName.SelectedItem.ToString();
            OleDbConnection dbconn = TheConnection();
            OleDbDataAdapter dadpter = new OleDbDataAdapter("Select QuizID from Quiz_Master where Quiz_Name = '" + selctdVal.Trim() + "'", dbconn);
            DataSet ds = new DataSet();
            dadpter.Fill(ds, "Quiz_Master");
            DataTable dt = ds.Tables[0];
            if(dt.Rows[0]["QuizID"].ToString() != string.Empty)
            {
                aa = dt.Rows[0]["QuizID"].ToString();
            }
            frmQuizName ff = new frmQuizName(aa, selctdVal);
            ff.Show();
            Close();
        }
        private void btncancel_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}


Any help in this regard will be appreciated. I am not familiar with Windows application..

Thanks in advance.
  #2 (permalink)  
Old October 17th, 2009, 06:17 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Quote:
It seems everyone in this forum works on Web Applications and I haven't found anyone helping out with Windows Applications . That's a pity.
Well, you posted this in an ASP.NET forum, so it's no surprise people here work with Web Applications, You're better off picking a different category for Win Form related questions, like this one: http://p2p.wrox.com/other-net-463/

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting values from Popupo window to parent form arnabghosh ASP.NET 3.5 Professionals 0 October 16th, 2009 01:00 PM
Problem in closing the parent window from a popup rakesh.kashnia1 Javascript 4 July 9th, 2007 05:39 AM
Centering Popup window & Blur Parent window jkusmanto Javascript How-To 0 May 25th, 2007 03:19 AM
How to pass values to main page from Popup window rmanmeet ASP.NET 1.0 and 1.1 Basics 1 January 5th, 2006 01:44 PM
refresh the parent window when closing the popup ram_siddinen VS.NET 2002/2003 1 January 30th, 2004 04:05 PM



All times are GMT -4. The time now is 11:32 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.