?
Solved

Delegate Event / Web application

Posted on 2006-04-11
3
Medium Priority
?
218 Views
Last Modified: 2010-04-16
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");
                              }
}

0
Comment
Question by:gbouch2
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
AGBrown earned 2000 total points
ID: 16428045
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
 

Author Comment

by:gbouch2
ID: 16428455

Thank you

It's working now ;-)

Sophie
0
 
LVL 12

Expert Comment

by:AGBrown
ID: 16428465
no problem

A
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Integration Management Part 2
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question