Hye IT Guys,
Few days back, I was working on loading dynamic control in asp.net. I found a problem. when ever I load a control, Its event is not firing for the first time. I found a solution for this problem i.e. We need to maintain the User Control ID so that its event remain attached with it.
See the below code.
protected void Page_Load(object sender, EventArgs e)
{
string ctrlName = "Controls/ctrlLogin.ascx";
string ctrlID = "uc1";
if (IsPostBack == false)
{
int ID = Convert.ToInt32(Request.QueryString["ID"]);
}
else
{
ctrlName = (string)ViewState["ctrlName"];
if (ctrlName != null)
{
Control uc = LoadControl(ctrlName);
uc.ID = ViewState["ctrlId"].ToString();
divContent.Controls.Add(uc);
}
}
}
Any suggestion or ideas will be appreciated. Thank You
Regards,
IT Guy