May 26 2007

Define Custom EventArgs in AJAX 1.0 Extensions

Category: AJAX-ATLASBil@l @ 15:47

While preparing a sample application to my new article on aspalliance.com that will be published soon on Creating Client Controls in ASP.NET 2.0 AJAX 1.0 Extensions, I had to bind an event handler to a button created in the render method of the control. Usually, event handlers are called with an empty argument which is of type Sys.EventArgs. However, to fire an event handler and pass in a parameter instead of the empty EventArgs, you use something similar to:

$addHandler(btn, 'click', Function.createCallback(this._clickDelegate, "MyData")); 

In the above line of code, you use the Function.createCallback function when you want to pass in some data instead of the empty EventArgs default class. In this case, we are passing a string that has the value of "MyData".

Another better and clean approach is to define a new custom EventArgs class. This way, you will feel yourself while developing in AJAX Client Side as if you are working with ASP.NET Servrer side. The class that I will define is the ContactEventArgs class which is as follows:

Type.registerNamespace("Bhaidar.AJAXComponents");

Bhaidar.AJAXComponents.ContactEventArgs= function(data) {
 Bhaidar.AJAXComponents.ContactEventArgs.initializeBase(this);
    this._data = data;
}

Bhaidar.AJAXComponents.ContactEventArgs.prototype= {
    get_data: function() {
        return this._data;
    },
    set_data: function(value) {
        this._data = value;
    }
}

Bhaidar.AJAXComponents.ContactEventArgs.registerClass('Bhaidar.AJAXComponents.ContactEventArgs', Sys.EventArgs);
Sys.Application.notifyScriptLoaded();

The class is very simply, I simply add a property called data to hold the data that are needed to be passed. The important thing to mention in defining this class is the following two lines:

Bhaidar.AJAXComponents.ContactEventArgs.initializeBase(this);
Bhaidar.AJAXComponents.ContactEventArgs.registerClass('Bhaidar.AJAXComponents.ContactEventArgs', Sys.EventArgs);

The first calls the constructor of the base class and in the second line you specify that this class inherits from the EventArgs class.

Now attaching a handler and passing some data can be done this way:

        var contactEventArgs = new Bhaidar.AJAXComponents.ContactEventArgs();
        contactEventArgs.set_data("MyData");
       
        $addHandler(btn, 'click', Function.createCallback(this._clickDelegate, contactEventArgs));

Isn't that clean and clear?

Hope this helps,
Regards
 


 

 

Tags:

May 25 2007

SQL Server Express and Read-Only Databases

Category: Databases & SQLBil@l @ 09:37

Several times, when I attach an existing database to SQL Server Express 2005, I get my database attached as read-only. So no way to add any object to it or update it!

The solution is to run this line:

Alter database <dbname> set read_write

As example would be: Alter database Northwind set read_write

This will make sure your database is now enabled for read/write!

 

Hope this helps,
Regards

Tags:

May 21 2007

My country is bleeding again ....

Category:Bil@l @ 21:30

Another barbaric attack hit my country, my city, my people, my children, my future, my body, my life!!!

Yesterday a car bomb in Achrafieh, tonight a car bomb in Verdun! Tomorrow? After tomorrow? After after tomorrow? What a life full of action and bomb surprises. What a life in Lebanon, its winter rains blood, its spring opens bombs insted of opening flowers, and its summer is hot as those bombs .....

Why are we supposed to pay that much? Till when are we supposed to keep on paying more and more?

I urge the UN and the international parties to stand-up and be responsible more and more to put an end to what is happening in this small country, but big in its people, LEBANON!!!

Nothing to say more ...

 

From the battale field - Beirut - Lebanon
Best Regards

Tags:

May 16 2007

A New Certificate Added ...

Category: General | GeneralBil@l @ 11:04

I have passed this morning the Designing and Developing Web Applications by Using the Microsoft .NET Framework exam with a score of 950/1000.