p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
I forgot my password Register Now
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 17th, 2009, 07:10 AM
Friend of Wrox
Points: 577, Level: 8
Points: 577, Level: 8 Points: 577, Level: 8 Points: 577, Level: 8
Activity: 5%
Activity: 5% Activity: 5% Activity: 5%
 
Join Date: Apr 2005
Location: Kolkata, West Bengal, India.
Posts: 115
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old October 17th, 2009, 07:17 AM
Imar's Avatar
Wrox Author
Points: 33,554, Level: 80
Points: 33,554, Level: 80 Points: 33,554, Level: 80 Points: 33,554, Level: 80
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,228
Thanks: 7
Thanked 203 Times in 201 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
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004

Did this post help you? Click the button to show your appreciation!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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 02:00 PM
Problem in closing the parent window from a popup rakesh.kashnia1 Javascript 4 July 9th, 2007 06:39 AM
Centering Popup window & Blur Parent window jkusmanto Javascript How-To 0 May 25th, 2007 04: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 02:13 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc