Delegate Event / Web application

Hi,

I have a web page, index.aspx, a usercontrol RequestSearch.ascx and a event class. CollectionRequestEventArgs.cs.

My problem is: I use eventhandler with my page and user control and my delegate is always null (crc variable). I don't know why.

I have my problem at these lines of codes
if (crc != null)
{
  crc(this, e);
}
  else{
           Response.Write("delegate is null");
}
      
Somebody could help me with this problem?

Thanks

Sophie

This the code od my project

When I call My user control in my aspx page I have this line of code:
<Request:Search runat="server" ID="RequestSearchControl" crc="searchControl_crc" />

In my page index.aspx I have this code in my codebehing:
protected void searchControl_crc(object sender, CollectionRequestEventArgs e)
{
     this.RequestList = e.SearchResultCollection;
     Response.Write("OK");
     Response.End();
}

private void InitializeComponent()
{    
    this.Load += new System.EventHandler(this.Page_Load);
    this.searchControl.crc +=new UserControl.RequestSearch.CollectionRequestChangedHandler(searchControl_crc);
}

In my CollectionRequestEventArgs.cs I have this code:

public class CollectionRequestEventArgs : EventArgs
      {
            public CollectionRequest2020 _searchResultCollection = new CollectionRequest2020();
            

            public CollectionRequest2020 SearchResultCollection
            {
                  set {_searchResultCollection = value;}
                  get
                  {
                        return _searchResultCollection;
                  }
            }
      }
}

And in my User control I have this code:

public class RequestSearch : System.Web.UI.UserControl
{
   public delegate void CollectionRequestChangedHandler(object sender, CollectionRequestEventArgs e);
   public event CollectionRequestChangedHandler crc;

   public void OnCollectionChanged(CollectionRequestEventArgs e)
            {
                  e.SearchResultCollection = this.RequestList;
                  Response.Write(e.ToString()+"\n");
                  if (e != null)
                  {
                        
                        //Response.Write();
                        if (crc != null)
                        {
                              crc(this, e);
                        }
                        else
                        {
                              Response.Write("delegate is null");
                        }
      
                  }
                  else
                  {
                        Response.Write("Args is null");
                  }
            }
public void btnSearch_Click(object sender, EventArgs e)
            {
                  
                  Request2020Object testObject = new Request2020Object();
                  CollectionRequest2020 List = new CollectionRequest2020();
                  testObject.RequestNumber = 100000;
                  testObject.Desc = "Test";
                  List.add(testObject);
                  this.RequestList = List;
                  this.OnCollectionChanged(new CollectionRequestEventArgs());
                  Response.Write("Event click Search Button\n");
                              }
}

gbouch2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AGBrownCommented:
There's a couple of things I notice on a cursory look:

>> When I call My user control in my aspx page I have this line of code:
>> <Request:Search runat="server" ID="RequestSearchControl" crc="searchControl_crc" />
>> ....
>> private void InitializeComponent()
>> {    
>>     this.Load += new System.EventHandler(this.Page_Load);
>>     this.searchControl.crc +=new UserControl.RequestSearch.CollectionRequestChangedHandler(searchControl_crc);
>> }

The id of the RequestSearch control in the aspx is set to RequestSearchControl, but in the InitialiseComponent method, you refer to a control with the ID SearchControl. Do you have 2 search controls, or just one? Try renaming SearchControl to RequestSearchControl. Once you have done that, also try removing the crc="searchControl_crc" attribute in the aspx. You should then have:

<Request:Search runat="server" ID="RequestSearchControl"/>

private void InitializeComponent()
{    
    this.Load += new System.EventHandler(this.Page_Load);
    this.RequestSearchControl.crc +=new UserControl.RequestSearch.CollectionRequestChangedHandler(searchControl_crc);
}

Does that help?

Andy
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gbouch2Author Commented:

Thank you

It's working now ;-)

Sophie
0
AGBrownCommented:
no problem

A
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.