problem in use delegate

Category: c# language

Question

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


hi

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; 
 
 
            this.OnOkButtonClicked(this); 
        }

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

thanks

Replies

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


http://msdn.microsoft.com/en-us/library/aa645739.aspx

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

thanks

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 http://forums.asp.net where you can contact ASP.NET experts.

  Sincerely,

  Jason Wang