• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

Define an event that fires CommandEventArgs

declared at top of my page:
public event EventHandler ItemsUpdated;

used in my code later on:
    if (this.ItemsUpdated != null)
                {
                          this.ItemsUpdated(this,EventArgs());
                }

I would prefer to fire a CommandEventArgs instead of the normal EventArgs, cause i I wamt to include how many items were updated.  How do I do this in c# please?
0
joshuadavidlee
Asked:
joshuadavidlee
  • 2
  • 2
1 Solution
 
dstanley9Commented:
Change it to:

public event CommandEventHandler ItemsUpdated;

used in my code later on:
    if (this.ItemsUpdated != null)
                {
                          string commandName = "{command name}";
                          Object argument = {argument(s)};
                          CommandEventArgs args = new CommandEventArgs(commandName, argument);
                          this.ItemsUpdated(this,args);
                }


0
 
joshuadavidleeAuthor Commented:
Error      1      The type or namespace name 'CommandEventHandler' could not be found (are you missing a using directive or an assembly reference?)      E:\Documents and Settings\Developer\My Documents\Visual Studio 2005\Projects\Tagger\Tagger\MyComponents\ChannelUpdater.cs      15      22      Tagger
0
 
dstanley9Commented:
It is defined in the System.Web.UI.WebControls namespace.  Add this namespace to your class using a "using" directive (and add a reference to the assembly if necessary).

That said, CommandEventArgs doesn't seem like the right fit for what you are trying to do.  If you want to include a parameter for the # of items updated, you could create your own event handler:

// define the delegate:
public delegate ItemsUpdatedEventHandler(object sender, ItemsUpdatedEventArgs e);

// define the event arguments
pblic class ItemsUpdatedEventArgs : EventArgs
{

  public ItemsUpdatedEventArgs(int itemsUpdated) : base()
  {
    _ItemsUpdated = itemsUpdated;
  }

  private int _ItemsUpdated int;
  public int ItemsUpdated {get {return _ItemsUpdated;}}
}


then your code would be:

public event ItemsUpdatedEventHandler ItemsUpdated;

used in my code later on:
     
    if (this.ItemsUpdated != null)
                {
                          int itemsUpdated = {# of items updated};
                          ItemsUpdatedEventArgs args = new ItemsUpdatedEventArgs(itemsUpdated);
                          this.ItemsUpdated(this,args);
                }
0
 
joshuadavidleeAuthor Commented:
public delegate void ItemsUpdatedEventHandler(object sender, ItemsUpdatedEventArgs e);
i think u forgot the word "void" but yes ok thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now