Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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)
        {
        }
    }
}
Posted
Comments
rajenh 20-Feb-13 14:31pm    
got the solution.
Using session variable we can do this
Sergey Alexandrovich Kryukov 20-Feb-13 14:33pm    
In what line do you have this exception thrown? What object is null, exactly? Please use the debugger.
—SA
rajenh 20-Feb-13 14:50pm    
in Webform2.cs label1.text is getting set to null.
Sergey Alexandrovich Kryukov 20-Feb-13 14:34pm    
And do yourself a big favor: never use auto-generated names like WebForm2, WebForm3... They violate naming conventions (designer just cannot do better, and should not). Always rename such name to something semantically sensitive...
—SA
rajenh 20-Feb-13 14:49pm    
Thank you for the guidance sir,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900