I am using below link for dynamically calling Usercontrols based on my conditions in aspx page. Link which i am using to dynamically load User-Controls
Now the question is that,
1) I am creating the object of respective user control, to call the submit functionality of that page. (is this the correct way to do this).
2) In the child page, ie(User Control), I get Object Reference Exception, while accessing the controls of this user control.
Can anybody please help.
Hi, Enclosing sample code for further clarification. 1) user Control code that i am using.
namespace WebApplication1
{
public partial class UserControlOne : System.Web.UI.UserControl
{
public void btnUserControlOne_Click(object sender, EventArgs e)
{
lblUserControlOne.Text = "User Control Button Clicked";
}
}
}
The error of object reference is coming at this line. lbl.Text.
2) The page where this user control is called is below.
namespace WebApplication1
{
public partial class parentWebForm : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.Web.UI.UserControl uc =
(System.Web.UI.UserControl)Page.LoadControl("UserControlOne.ascx");
divLoadControl.Controls.Add(uc);
}
protected void btnParent_Click(object sender, EventArgs e)
{
UserControlOne usrCntrlOne = new UserControlOne();
usrCntrlOne.btnUserControlOne_Click(sender, e);
}
}
}