EventArgs Example
In one my past posts, I talked about that CryptoCollaboration using the EventArgs base class because it keeps things nice and generalized, allowing for expanasion for the handling of future event integration. A person emailed me and asked for a practical example of when would use such a thing in a SharePoint WebPart. Eh, ok.
I am going to use an example of a progress class, that, well, as you can guess will display the progress of some sort of execution that happens with a SharePoint WebPart.
The first class is the Process Arguments class (ProcessArgs), that inherits from the EventArgs base class.
-
public class ProgressArgs : EventArgs
-
{
-
private int m_nPercentageComplete = 0;
-
private DataRow m_oDataRow;
-
-
public ProgressArgs(DataRow dataRow, int percentageComplete)
-
{
-
this.m_oDataRow = dataRow;
-
this.m_nPercentageComplete = percentageComplete;
-
}
-
-
public DataRow CurrentDataRow
-
{
-
get
-
{
-
return this.m_oDataRow;
-
}
-
}
-
-
public int PercentageComplete
-
{
-
get
-
{
-
return this.m_nPercentageComplete;
-
}
-
}
-
}
In the next class, there will be the establishment of the event handler that will be called from a sister class by use of a delegate.
-
public delegate void ProgressEventHandler(object sender, ProgressArgs e);
Now that the delegate is established, you can call it in some general class file.
-
public event ProgressEventHandler ProgressEvent;
-
-
protected virtual void OnProgress(ProgressArgs e)
-
{
-
if (this.ProgressEvent != null)
-
{
-
this.ProgressEvent(this, e);
-
}
-
}
Then calculate out the progress.
-
ProgressArgs e = new ProgressArgs(row, (int) ((((double) num) / ((double) this.DBDataTable.Rows.Count)) * 100));
-
this.OnProgress(e);
I am not saying that this is the only way to do it, but with applications that you plan on extending later it is the route that I have choosen to go in the past. I may at some point explore the deficiencies in a such an approach, however at this current time I just want to finish the damn thing.
Related posts:
- Event Handling In InfoPath
- CryptoCollaboration Client Testing / Encryption Optimization
- Using the Wizard Control In WebParts
- Open Configuration Panel From WebPart ToolPane
- Protected Constructors For Abstract Classes
No Comments »
No comments yet.
RSS feed for comments on this post. TrackBack URL























Articles & Research
SharePoint Architecture
Research Methodology
Personal/Off-Topic
Article Or Research Filed Under 
