Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1058941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:05:54+00:00 2026-05-16T18:05:54+00:00

I am using C# and Visual Studio 2005. I have created multiple Texboxes at

  • 0

I am using C# and Visual Studio 2005.

I have created multiple Texboxes at runtime in FlowlayoutPanel. It works fine, but when I am trying to dispose null textboxes and put message like below.

    void tbb_KeyPress(object sender, KeyPressEventArgs e)
    {
        if ((Keys)e.KeyChar == Keys.Enter)
        {
            listBox2.Visible = false;
            button4.Visible = false;
            if (tbb.Text!="")
            {
                bb.Visible = true;
                bb.Focus();
            }
            else
            {
                //tbb.Visible = false;
                tbb.Dispose();
                bb.Dispose();
                textBox2.Visible = true;
                textBox2.Focus();
            }
        }
    }

The above code works fine and disposing at runtime well.
The data saving code is:

private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
    if ((Keys)e.KeyChar == Keys.Enter)
    {
        if (bb.Text == "")
        {
            MessageBox.Show("Sorry Empty.Row");
            this.flowLayoutPanel1.Controls.Clear();
            label13.Text = "";
            textBox1.Text = "";
            textBox2.Text = "";
            maskedTextBox1.Text = "";
            maskedTextBox1.Enabled = true;
            maskedTextBox1.Focus();
            textBox1.Enabled = true;
        }
        else
        {
            string connstr = "server=.;initial catalog= maa;uid=mah;pwd=mah";
            SqlConnection con = new SqlConnection(connstr);
            con.Open();

            SqlCommand cmd1 = new SqlCommand("insert into debankA(companyID,transID,date,bank,totdepo,narrat) values " +
            "(@companyID,@transID,Convert(datetime,'" + maskedTextBox1.Text.ToString() + "',103),@bank,@totdepo,@narrat)", con);
            cmd1.Parameters.Add("@bank", SqlDbType.VarChar).Value = textBox1.Text;
            cmd1.Parameters.Add("@totdepo", SqlDbType.Decimal).Value = label13.Text;
            cmd1.Parameters.Add("@narrat", SqlDbType.VarChar).Value = textBox2.Text;
            cmd1.Parameters.Add("@companyID", SqlDbType.Int).Value = label6.Text;
            cmd1.Parameters.Add("@transID", SqlDbType.Int).Value = textBox4.Text;
            cmd1.ExecuteNonQuery();

            string pparticulars = null;
            double? depo = null;
            string messs = "Record Save Successfully";
            foreach (Control ctl in this.flowLayoutPanel1.Controls)
            {
                if (ctl.Name.Contains("tbb") && ctl is TextBox)
                {
                    pparticulars = ctl.Text;
                }

                if (ctl.Name.Contains("bb") && ctl is TextBox)
                {
                    double ddepo = 0;

                    if (double.TryParse(ctl.Text, out ddepo))

                        depo = ddepo;

                    if (pparticulars != null && depo != null)
                    {
                        SqlCommand cmd = new SqlCommand("insert into debankB(particulars,deposit,companyID,transID)values" +
                        "(@particulars,@deposit,@companyID,@transID)", con);
                        cmd.Parameters.Add("@particulars", SqlDbType.VarChar).Value = pparticulars;
                        cmd.Parameters.Add("@deposit", SqlDbType.Decimal).Value = depo;
                        cmd.Parameters.Add("@companyID", SqlDbType.Int).Value = label6.Text;
                        cmd.Parameters.Add("@transID", SqlDbType.Int).Value = textBox4.Text;
                        cmd.ExecuteNonQuery();
                        pparticulars = null;
                        depo = null;

                        MessageBox.Show(messs);
                        messs = null;
                        this.flowLayoutPanel1.Controls.Clear();
                        label13.Text = "";
                        textBox1.Text = "";
                        textBox2.Text = "";
                        maskedTextBox1.Text = "";
                        maskedTextBox1.Enabled = true;
                        maskedTextBox1.Focus();
                        textBox1.Enabled = true;
                    }

Even though I have disposed both empty textboxes message always show only “empty.records” as above I set.

That means the empty textboxes are not disposed. But if it is true then when I have run the application and created textboxes where is data available it remains the same and empty textboxes are not visible. Disposing on enter.

I don’t understand what is the problem. If the textbox is disposed during runtime then how can it show as empty?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:05:54+00:00Added an answer on May 16, 2026 at 6:05 pm

    What are you trying to accomplish by disposing the controls?

    Disposing an object means that you tell it to remove all unmanaged resources, because you are not going to use the object any more. For a winform control like a TextBox this means that it frees the actual windows control, but it doesn’t mean that the TextBox object goes away.

    If you want to remove controls from the page, you should first remove the object from the control tree, then you can dispose it. If you just dispose it, you leave a control object in the page, but without a corresponding window control to be displayed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The Outlook add-ins I have created using Visual Studio 2005 don't use the ClickOnce
I'm using Visual Studio C++ 2005 on Windows XP. I have created a DLL
Visual Studio 2005 I have developed an application using C#. I have created an
I have created a windows service using Visual Studio 2005. I have created a
I am using Crystal Reports inside Visual Studio 2005. I have created a report
I'm using Visual Studio 2005 and have a DataTable with two columns and some
(Using Visual Studio 2005 / .NET 2.0) I have a DataSet which is being
I'm using Visual Studio 2005 on a Windows XP SP3 machine and recently have
I'm using Visual Studio 2005 with VB.NET. I have a number of Crystal Reports,
I have CruiseControl.net running Visual Studio (2005/2008 - using devenv.com) as we need to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.