**When I pass the value from Form1 to user control and display the value that I get from Form1, it displays null.My user control is contained within another form, Form2.
Form 1 code:**
namespace test
{
public partial class Form1 : Form
{
String user;
public Form1()
{
InitializeComponent();
}
private void Login_btn_Click(object sender, EventArgs e)
{
user = username.Text;
MyuserControl ctrl = new MyuserControl();
ctrl.Data = user; //will send the value of the user to the Data
}
}
}
User Control code:
namespace test
{
public partial class MyuserControl : UserControl
{
Private String data;
public String Data { get { return data; } set { data = value; } }
public MyuserControl()
{
initializeComponent();
}
private void MyuserControl(object sender, EventArgs e)
{
label1.Text = Data;
}
}
}
I tried using constructors, getters, and setters. However, when I apply this to Form2 instead of user controls, it successfully passes the value.
I want the value to be passed on my user control.
user25280532 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.