Click here to Skip to main content
12,634,101 members (26,509 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP .NET
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 20-Feb-13 7:12am
rajenh410
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.161208.2 | Last Updated 20 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100