Here is my DynamicUserControl.Aspx code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class DynamicUserControl : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["test"] = null;
}
int id = 1;
if (Session["test"] != null)
{
id = int.Parse(Session["test"].ToString());
}
if (Session["test"] == null)
{
UserControl_WebUserControl1 ucSimpleControl = (UserControl_WebUserControl1)LoadControl("~/UserControl/WebUserControl" + id + ".ascx");
ControlHolder.Controls.Clear();
ControlHolder.Controls.Add(ucSimpleControl);
ucSimpleControl.Next1Click += new EventHandler(ucSimpleControl_Next1Click);
}
if (id == 2)
{
UserControl_WebUserControl2 ucSimpleControl = (UserControl_WebUserControl2)LoadControl("~/UserControl/WebUserControl" + id + ".ascx");
ControlHolder.Controls.Clear();
ControlHolder.Controls.Add(ucSimpleControl);
ucSimpleControl.Next2Click += new EventHandler(ucSimpleControl_Next2Click);
}
if (id == 3)
{
UserControl_WebUserControl3 ucSimpleControl = (UserControl_WebUserControl3)LoadControl("~/UserControl/WebUserControl" + id + ".ascx");
ControlHolder.Controls.Clear();
ControlHolder.Controls.Add(ucSimpleControl);
ucSimpleControl.Next3Click += new EventHandler(ucSimpleControl_Next3Click);
}
}
protected void ucSimpleControl_Next1Click(object sender, EventArgs e)
{
Response.Write("It's working");
}
protected void ucSimpleControl_Next2Click(object sender, EventArgs e)
{
Response.Write("It's working");
}
protected void ucSimpleControl_Next3Click(object sender, EventArgs e)
{
Response.Write("It's working");
}
}
My FirstUsercontrol.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class UserControl_WebUserControl1 : System.Web.UI.UserControl
{
public event EventHandler Next1Click;
protected void Page_Load(object sender, EventArgs e)
{
Session["test"] = null;
}
protected void Next1_Click(object sender, EventArgs e)
{
Session["test"] = "2";
UserControl_WebUserControl2 ucSimpleControl = (UserControl_WebUserControl2)LoadControl("~/UserControl/WebUserControl2.ascx");
PlaceHolder phContactDetails = (PlaceHolder)Page.FindControl("ControlHolder");
phContactDetails.Controls.Clear();
phContactDetails.Controls.Add(ucSimpleControl);
ucSimpleControl.Next2Click += new EventHandler(ucSimpleControl_Next2Click);
}
protected void ucSimpleControl_Next2Click(object sender, EventArgs e)
{
Response.Write("It's working");
}
}
my second usercontrol.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class UserControl_WebUserControl2 : System.Web.UI.UserControl
{
public event EventHandler Next2Click;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Next2_Click(object sender, EventArgs e)
{
Session["test"] = "3";
UserControl_WebUserControl3 ucSimpleControl = (UserControl_WebUserControl3)LoadControl("~/UserControl/WebUserControl3.ascx");
PlaceHolder phContactDetails = (PlaceHolder)Page.FindControl("ControlHolder");
phContactDetails.Controls.Clear();
phContactDetails.Controls.Add(ucSimpleControl);
ucSimpleControl.Next3Click += new EventHandler(ucSimpleControl_Next3Click);
}
protected void ucSimpleControl_Next3Click(object sender, EventArgs e)
{
Response.Write("It's working");
}
}
my third usercontrol.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class UserControl_WebUserControl3 : System.Web.UI.UserControl
{
public event EventHandler Next3Click;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Next3_Click(object sender, EventArgs e)
{
Next3Click(sender, e);
}
protected void UserControl_WebUserControl1_Next3Click(object sender, EventArgs e)
{
Response.Write("It's working fine");
}
}
please help me why from second user control we have to click the button twice for firing next button events.
Thanks in Advance.
[edit]Code blocks added - OriginalGriff[/edit]