1 Replies - 662 Views - Last Post: 18 January 2013 - 07:39 AM Rate Topic: -----

#1 arsr249  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-January 13

unable to access value from usercontrol

Posted 18 January 2013 - 03:36 AM

I am trying to access value from usercontrol called Addrow from a form called time sheet ,but when I click the save_btn which is in the timesheet form textbox is empty,the value it a empty string ,below is the code

        public void save_btn_Click(object sender, EventArgs e)
            SqlCommand cmdinsert = new SqlCommand("insert into TimeSheet (Project_Name,Activity_Name, Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday) values (@Project_Name,@Activity_Name, @Monday,@Tuesday,@Wednesday,@Thursday,@Friday,@Saturday,@Sunday) ", con);
            cmdinsert.Parameters.AddWithValue("@Project_Name", add.project_cbox.SelectedIndex);
            cmdinsert.Parameters.AddWithValue("@Activity_Name", activity_cb.SelectedIndex);
            cmdinsert.Parameters.AddWithValue("@Monday", add.monday_txt.Text);
            cmdinsert.Parameters.AddWithValue("@Tuesday", add.tuesday_txt.Text);
            cmdinsert.Parameters.AddWithValue("@Wednesday", add.wednesday_txt.Text);
            cmdinsert.Parameters.AddWithValue("@Thursday", add.thursday_txt.Text);
            cmdinsert.Parameters.AddWithValue("@Friday", add.friday_txt.Text);
            cmdinsert.Parameters.AddWithValue("@Saturday", add.saturday_txt.Text);
            cmdinsert.Parameters.AddWithValue("@Sunday", add.sunday_txt.Text);

I tried accessing using properties ,I want to if there is a way to access the value in usercontrol without having to create an new instance of usercontrol in the form,also textboxes created are dynamic,any help will be much appreciated

Is This A Good Question/Topic? 0
  • +

Replies To: unable to access value from usercontrol

#2 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6528
  • View blog
  • Posts: 14,438
  • Joined: 02-June 10

Re: unable to access value from usercontrol

Posted 18 January 2013 - 07:39 AM

You should never access GUI controls between forms like that. It is horrible practice. Make a property for the values you want to receive. See the the properties tutorial linked in my signature block.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1