D
DotNetGuru
Hi,
I have nested User Controls like below.
User_Control_1
User_Control_11
User_Control_12(contains method DisplayMessage)
User_Control_2(contains event onButtonClick )
User_Control_1 and User_Control_2 are loaded in the PAGE_LOAD of a
Layout.aspx. This aspx page WIRES the event of the control
User_Control_2(event onButtonClick) to the method of
User_Control_12(DisplayMessage) as below
oControl2.onButtonClick = new
EventHandler(oControl1.oControl11.oControl12.DisplayMessage);
The error returned is "Object reference not set to an instance of an
object."
Control12 is loeaded in Control11 and control11 is loaded in Control1.
Control1 is loaded in Layout.aspx. I do not want to use BubbleEvent.
Isn't there a simpler way of getting these controls connected. Below
is my code... Help appreciated
Below is the code of Layout.ascx.cs
public class Layout : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlTableCell tblcellControl1;
protected System.Web.UI.HtmlControls.HtmlTableCell tblcellControl2;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
NestedControls.Control1 oControl1 = (Control1)
LoadControl("Control1.ascx");
tblcellControl1.Controls.Add(oControl1);
NestedControls.Control2 oControl2 = (Control2)
LoadControl("Control2.ascx");
tblcellControl2.Controls.Add(oControl2);
oControl2.onButtonClick = new
EventHandler(oControl1.oControl11.oControl12.DisplayMessage);
}
Below is the code for Control2
public abstract class Control2 : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
public EventHandler onButtonClick
{
set{this.Button1.Click +=value; }
}
Below is the code for Control12(method to wire to)
public void DisplayMessage(object sender, EventArgs e)
{
Response.Write("Button Clicked of Control_12");
}
Please help me sort this problem.
Thank You.
Guru
I have nested User Controls like below.
User_Control_1
User_Control_11
User_Control_12(contains method DisplayMessage)
User_Control_2(contains event onButtonClick )
User_Control_1 and User_Control_2 are loaded in the PAGE_LOAD of a
Layout.aspx. This aspx page WIRES the event of the control
User_Control_2(event onButtonClick) to the method of
User_Control_12(DisplayMessage) as below
oControl2.onButtonClick = new
EventHandler(oControl1.oControl11.oControl12.DisplayMessage);
The error returned is "Object reference not set to an instance of an
object."
Control12 is loeaded in Control11 and control11 is loaded in Control1.
Control1 is loaded in Layout.aspx. I do not want to use BubbleEvent.
Isn't there a simpler way of getting these controls connected. Below
is my code... Help appreciated
Below is the code of Layout.ascx.cs
public class Layout : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlTableCell tblcellControl1;
protected System.Web.UI.HtmlControls.HtmlTableCell tblcellControl2;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
NestedControls.Control1 oControl1 = (Control1)
LoadControl("Control1.ascx");
tblcellControl1.Controls.Add(oControl1);
NestedControls.Control2 oControl2 = (Control2)
LoadControl("Control2.ascx");
tblcellControl2.Controls.Add(oControl2);
oControl2.onButtonClick = new
EventHandler(oControl1.oControl11.oControl12.DisplayMessage);
}
Below is the code for Control2
public abstract class Control2 : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
public EventHandler onButtonClick
{
set{this.Button1.Click +=value; }
}
Below is the code for Control12(method to wire to)
public void DisplayMessage(object sender, EventArgs e)
{
Response.Write("Button Clicked of Control_12");
}
Please help me sort this problem.
Thank You.
Guru