I have a user control that will supposedly pass value to its parent form which is form1.
I used the code below.
User Control
public int _control;
public int control
{
get{return _control;}
set{_control=value;}
}
Form1 assign value to UserControl
UserControl1 uc=new UserControl1();
uc.control=1;
User Control Button_Click
var parent = this.Parent as Form1;
//MessageBox.Show(_control.ToString());
parent.userNo=_control;
Form1
public int _userNo;
public int userNo
{
get{return _userNo;}
set{_userNo=value;}
}
The problem is when i used messagebox.show, it will appear displaying 1 but when i used
parent.userNo=_control;
it returns a Null Reference Exception.
Please help!!!