Mar 29 2008

Ready-Made Delegates in .NET 2.0

Category:Bil@l @ 22:31

Sometimes while writing your code you need to create new delegates to meet your specific project requirements to call specific methods. Before directly opening a new CS or VB class and start adding new delegates, make sure to check the read-made delegates introduced by .NET 2.0. Some of these are listed here:

 

.NET 2.0 Read-Made Delegates

1. delegate Boolean Predicate<T>(T obj);

This is a delegate that can hold a reference to a method that takes as input a parameter of type T and returns boolean.

 

2. delegate void Action<T>(T obj);

This is a delegate that can hold a reference to a method that takes as input a parameter of type T and returns nothing.

 

3. delegate void MethodInvoker();

This is a delegate that can hold a reference to a method that takes no input parameters and returns nothing.

 

In .NET 3.5 new delegates were added:

delegate void Action();

delegate void Action<T1, T2>(T1 arg1, T2 arg2);

delegate void Action<T1, T2, T3>(T1 arg1, T2 arg2);

delegate void Action<T1, T2, T3, T4>(T1 arg1, T2 arg2,T3 arg3, T4 arg4);

delegate TResult Func<TResult>();

delegate TResult Func<T, TResult>(T arg);

delegate TResult Func<T1, T2, TResult>(T1 arg1, T2 arg2);

delegate TResult Func<T1, T2, T3, TResult>(T1 arg1, T2 arg2);

delegate TResult Func<T1, T2, T3, T4, TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4);

 

The above delegates are self explained. So now, when you need a new delegate, check the existing ones before creating your own! The above delegates are all present inside the System namespace.

 

Hope this helps,
Regards

Tags:

Mar 28 2008

Microsoft - LebDev Visual Studio and Windows Server 2008 Community Launch

Category:Bil@l @ 21:54

Today we had the LebDev user group version of the Community Launch for Visual Studio 2008 and Windows Server 2008 at the Gefinor - Rotana Hotel - Hamra. The session started at 6 and lasted for 3 hours.

Maral Topalian delivered a session on Windows Server 2008

I presented a demo-ish session by developing a simple blog engine using LINQ to SQL, AJAX, ASP.NET 3.5, VS 2008. You can download the PPTX and code from here: Presentation (https://bhaidar.net/cs_files/MSFT-Launch-2008.zip) and Sample code(https://bhaidar.net/cs_files/MSFTLaunch2008.zip).

Wessam Zeidan (www.wessamzeidan.net) then delivered another demo-ish presentation on Silverlight 2.0, WPF, and ADO.NET Data Services.

The next stop is the official Microsoft Launch on April 30! I will be delivering something, not sure yet what it is :)

 

Hope this helps,
Regards

Tags:

Mar 27 2008

Intellisense with Client-side Proxy Classes in AJAX

Category:Bil@l @ 22:22

I was trying to find out how to enable JavaScript Intellisense for webservices' client-side proxy classes when we are accessing client-proxy classes in external JS files?

I couldn't find a simpler solution than to:

  1. Run the application
  2. Download the client-side proxy class
  3. Save the content to a JavaScript file as the name of the Webservice and the extension of .js
  4. Add a /// <reference path="MyProxy.js" /> to the external JS file
  5. Intellisense enabled!

Is there an easier way of doing the same?

 

Regards

Tags:

Mar 27 2008

AJAX Client Library Presentation @ Microsoft Office

Category:Bil@l @ 17:37

Yesterday I delivered a session on ASP.NET 2.0 AJAX Extensions 1.0 - Client Library.

This presentation was part of a two-days free training Wessam Zeidan (www.wessamzeidan.net) and I delivered for a selected group of the Lebanese developers that are part of the LebDev.NET User Group members.

 

You can download the pptx file from here (https://bhaidar.net/cs_files/Ajax-Basics-Client-Library.zip).

As for the sample codes, you can follow the source code that ships with the book: AJAX in Action (http://www.manning.com/gallo/). I have used the same code to show some samples!!

 

Hope this helps,
Regards

Tags:

Mar 27 2008

Client Application Services Part 3

Category: ASP.NET 3.5 | Windows FormsBil@l @ 14:25

My third article in the series of articles on Client Application Services is now published on www.aspalliance.com. This is the last article in the aforementioned series! Hope you enjoy it! You can check it at: Client Application Services Part 3 (http://aspalliance.com/1597_Client_Application_Services__Part_3).

Make sure to read the previous two parts before going on with this new part! Here are the links for Parts 1 and 2.

 

  1. Client Application Services Part 1 (http://aspalliance.com/1595_Client_Application_Services__Part_1)
  2. Client Application Services Part 2 (http://aspalliance.com/1596_Client_Application_Services__Part_2)

 

Hope this helps,
Regards

Tags: ,

Mar 27 2008

Nested MasterPage Not Firing Page_Load Event

Category: ASP.NET 2.0 - General | ASP.NET 3.5Bil@l @ 11:42

I faced a situation today where I am trying to attach to the page_load event of a child nested master page to load some data on the master page itself. The event was not firing at all. Later on I figured out that the AutoEventWireup property on the Page directive is false!!!

Seems by default when you create a nested master page, its AutoEventWireup property is set to false! What you need to do is just make it true!

 

Hope this helps!

Regards

Tags: ,

Mar 27 2008

RowIndex inside ListView_ItemDataBound event

Category:Bil@l @ 10:10

If you need to access DataKeys of a ListView from inside the ItemDataBound you need to use the ListViewDataItem class. The ListViewDataItem class represents an individual data item in the ListView control. Every data item refers to a record in the data source.

The trick is to use the ListViewDataItem.DisplayIndex property! This property returns the index of the currently bound row inside the ListView collection of items.

A sample code could help more:

protected void PostList_ItemDataBound(object sender, ListViewItemEventArgs e)
{
    // Get the listview
    ListView listView = (ListView)sender;

    //Get the item object.
    ListViewDataItem dataItem = (ListViewDataItem)e.Item;

    // Only data items are allowed
    if (e.Item.ItemType != ListViewItemType.DataItem) return;

    // Get the PostID from the ListView's datakey
    int postID = int.Parse(listView.DataKeys[dataItem.DisplayIndex].Value.ToString());

}

 

The ListView DataKeyNames had a value of "PostID" which represents the primary key column in the data table.

First of all you cast the e.Item property to an instance of ListViewDataItem, then using the DisplayIndex property you can access the DataKeys of the currently bound row!

 

Hope this helps,
Regards

Tags:

Mar 25 2008

Using The Silverlight DataGrid

Category:Bil@l @ 07:19

A very nice walkthrough on using the new Silverlight DataGrid can be reached here: Using The Silverlight DataGrid (http://blogs.msdn.com/scmorris/archive/2008/03/21/using-the-silverlight-datagrid.aspx).

This tutorial is by Scott Morrison (http://blogs.msdn.com/scmorris/).

 

Hope you enjoy it!
Regards

Tags:

Mar 25 2008

ASP.NET MVC Source Code Now Available

Category:Bil@l @ 07:16

Scott Guthrie announced few days ago that the ASP.NET MVC Source Code is now available on www.codeplex.com

In fact, MSFT opened up a new ASP.NET CodePlex project (http://codeplex.net/aspnet) to share the source code of several ASP.NET related upcoming project releases.

Read on on Scott's post here (http://weblogs.asp.net/scottgu/archive/2008/03/21/asp-net-mvc-source-code-now-available.aspx)

 

Thank you Microsoft!

Regards

Tags:

Mar 24 2008

Happy Easter

Category:Bil@l @ 07:00

I want to wish you a Happy Easter for all those who had their easter yesterday! May this easter bring you the hope, love, safety, and prosperity!

Happy Easter!

Regards

Tags: