Wednesday, January 25, 2006

Wicked Code asp.net 2.0 -- (feature 5/5)

Feature 5: Custom Web Events

PROBLEM:
How easy it is to create our own Custom Web Events in .net 2.0?

SOLUTION:
http://msdn.microsoft.com/library/en-us/dnvs05/html/custwebcon.asp
http://www.asp.net/QuickStart/aspnet/doc/monitoring/webevents.aspx

Analyze this code:-
using System;
using System.Web.Management;
using System;using System.Web;
using System.Web.Management;

public partial class WebEvent_aspx
{
void Button1_Click (object sender, EventArgs e)
{
MyWebEvent mwe = new MyWebEvent ("Click!", null, 100001, DateTime.Now); WebBaseEvent.Raise (mwe);
}
}


public class MyWebEvent : WebBaseEvent
{
DateTime _time;

public MyWebEvent (string message, object source, int eventCode, DateTime time) : base (message, source, eventCode)
{ _time = time; }

public override void FormatCustomEventDetails( WebEventFormatter formatter)
{ formatter.AppendLine ("Button clicked at " +_time.ToString()); }
}

No comments: