problem in use delegate

Category: c# language


vahidbakhtiary on Tue, 16 Oct 2012 10:12:33


i have a tree in a user control and i want when nodes is change my information in aspx page be change

i create a class called CustomArg.cs

public delegate void OnOkButtonClick(object sender,CustomArg e); 
public class CustomArg : EventArgs 
    public decimal PERno { get; set; } 
    public string FullName { get; set; } 

i have a user control called Treel.ascx

 public event  OnOkButtonClick OnOkButtonClicked; 
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e) 
            CustomArg args = new CustomArg(); 
            args.PERno = Convert.ToDecimal(TreeView1.SelectedNode.Value); 
            args.FullName = TreeView1.SelectedNode.Text; 

and i have a aspx page called EnterExit

 protected void Page_Load(object sender, EventArgs e) 
            Forms_Treel obj = new Forms_Treel(); 
            obj.OnOkButtonClicked += new OnOkButtonClick(obj_OnOkButtonClicked); 
void obj_OnOkButtonClicked(object sender,CustomArg e) 
            //tbInforamtion.Visible = true; 
            //lblFullName.Text = e.FullName; 
            //lblPno.Text = e.PERno.ToString(); 

and i drag from user control to EnterExit.aspx page

now wehen i run it this error :

Object reference not set to an instance of an object.

please help me for solve it



Berrettini Luigi on Tue, 16 Oct 2012 10:30:39

Maybe you forgot the if (OnOkButtonClicked != null)..

vahidbakhtiary on Tue, 16 Oct 2012 10:38:26

thanks for your answer

my problem is it,becuse the OnOkButtonClicked  is always null

please say to me what is my problem


Viorel_ on Tue, 16 Oct 2012 18:42:41

Your user control is Treel and your form is EnterExit. What is Forms_Treel and why it is created inside Page_Load?

Jason Dot Wang on Thu, 18 Oct 2012 06:55:23

Hi vahidbakhtiary,

  Welcome to MSDN Forum Support.


  You are more likely to get more efficient responses to ASP.NET issues at where you can contact ASP.NET experts.


  Jason Wang