I'm new to usercontrol and wanted to learn its application. I rendered my user control in a web form.
I want to get data to my web page from user control but I'm not getting it, I am facing some NULLRefrence error regarding user control controls. Here is my code for both .ascx and .aspx
ascx.cs
protected void Page_Load(object sender, EventArgs e)
{
}
private string userName;
private int userAge;
private string userCountry;
public string UserName
{
get { return txt_name.Text; }
set { txt_name.Text = value; }
}
public int UserAge
{
get { return userAge= Convert.ToInt32(txt_age.Text); }
set { userAge = value; }
}
public string UserCountry
{
get { return ddl_country.Text; }
set { ddl_country.Text = value; }
}
Is there is any problem with my get and set property, please help me to find out the error.
You can use user control by registering user control on the page where you want to use it like this
<%@ Register TagName="MyControl" TagPrefix="MyCtrl" Src="~/UserControls/MyUserControl.ascx" %>
And than to render the control you have to write this
<MyCtrl:MyControl runat="server" />
This will render the control on the place where you will write this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With