I have used 3 webforms
webform1 contains multicast delegate
webfomr2 contains method Callme()and a label Control
webform3 also contains the same as webform2.
Now when i invoke the multicast delegate i'm getting null reference error. I know that some where the object is getting reset to null.
But why its getting reset to null ?
Code behind file
Webform1.cs
----------------
namespace MultiCasteExample
{
public partial class WebForm1 : System.Web.UI.Page
{
public delegate void CallEveryOne();
public void method1()
{
CallEveryOne objcall = null;
WebForm2 obj1 = new WebForm2();
WebForm3 obj2 = new WebForm3();
objcall += obj1.CallMe;
objcall += obj2.CallMe;
objcall.Invoke();
}
protected void Page_Load(object sender, EventArgs e)
{
method1();
}
}
}
WebForm2.cs
-----------------
namespace MultiCasteExample
{
public partial class WebForm2 : System.Web.UI.Page
{
public void CallMe()
{
Label1.Text = "ErrorMessage BroadCasted at " + DateTime.Now.ToString();
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
WebForm3.cs
--------------
namespace MultiCasteExample
{
public partial class WebForm3 : System.Web.UI.Page
{
public void CallMe()
{
Label1.Text = "Error Message is broadcasted at" + DateTime.Now.ToString();
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
}