Thursday, May 05, 2005

Kieran Lynam will be giving a talk on ASP.Net 2.0 to NIMTUG members on Monday 16th May in Belfast. For more information and to register for the talk (which is free) visit http://nimtug.org/16-May-2005.aspx

Thursday, May 05, 2005 4:54:35 PM (GMT Daylight Time, UTC+01:00)  #    Comments [1]Trackback
 Monday, April 25, 2005

This will probably be the last feature update of my AJAX library as it does all I need the moment, but please keep sending me your suggestions as you never know.

Update:

New feature: you now have the ability to pass complex types as parameters. The IAjaxJavaScriptObjectConverter interface has been enhanced and now allows you to define format functions for formatting JavaScript objects into strings that can be passed as parameters.

Web.config: the attribute for adding converters has been changed from 'type' to 'converter'

New Demo: I've created a DateTime converter and extended the StringCollection to include the new features. You can use these as your skeleton converters.

I've also included another demo that allows you to send a complex type as a parameter.

Online demos: The demos are now online after a couple of requests.

Potential Problem: When converting an object to be returned into JavaScript the default converter loops through all the properties and fields and converts them too. Some types reference their parents and these types will cause a memory problem as they will be caught in an infinite loop. To ensure that this does not happen only return types that are known not to do this and if you do require a type that references it parent (or its children which causes the same problem) then write a custom converter and control the conversion process. I was considering requiring that all return types must be referenced in the web.config - but due to the added complexity decided not too. So check all types before returning them!

 

Download  Demos

Monday, April 25, 2005 4:01:17 PM (GMT Daylight Time, UTC+01:00)  #    Comments [1]Trackback
 Saturday, April 23, 2005

Update:

It was pointed out to me by Manu Seiber that not everyone has write access to the /aspnet_client/system_web/[framework version]/ directory and so can't upload the 'ajax.js' file making the library useless. Now I've added the ability to set the javascript directory that the 'ajax.js' file is located. For backward compaitability it defaults to /aspnet_client/system_web/[framework version]/ if not set.

See JavaScript File section in Read Me file.

Download

 |  | 
Saturday, April 23, 2005 10:40:18 AM (GMT Daylight Time, UTC+01:00)  #    Comments [7]Trackback
 Thursday, April 21, 2005

Changes:

  • You now export types with the method TypeExporter.Export instead of MethodHelper.Register
  • Exceptions now work properly

A coupe of people mentioned a bug when pressing F5 could they please give me more details on this and check if the bug is in this release.

http://mcgiv.com/blog/ajax/

 

 |  | 
Thursday, April 21, 2005 9:49:20 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]Trackback
 Tuesday, April 19, 2005

Bug fix:Strings are now encoded before sent to the server, although there are still some problems with unicode characters.

Change:Instead of having to Register the custom Type converters they are now placed in the "ajax" section of web.config. The benifits are that converters can be updated with out having to recompile the whole project. The ajax.js file has been updated so this will have to be replaced.

download AJAX for APS.Net

Using:

within <configuration> add the following

<configSections>

<section name="ajax" type="Ajax.AjaxConfigurationSectionHandler, Ajax" />

</configSections>

and then add each of the converters as below

<ajax>

<add type="Full Type Name, Assembly Name" />

<add type="Ajax.Web.DataTableConverter, Ajax.Web" />

</ajax>

 |  | 
Wednesday, April 20, 2005 6:38:40 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]Trackback

I've updated the Ajax library and added some more functionality.

Thanks to Michael Schwartz for pointing out a security bug - when invoking a method it wasn't checked to see if it had the JavaScriptAccessableMethodAttribute attribute. He also pointed out that DateTime and TimeSpan were not handeled properly - this is also corrected.

Added functionality:

You can now write your own Object Type to JavaScript convert and register it which then overrides the conversion the type from the default.

Converters must implement the IAjaxJavaScriptObjectConverter interface.

    public interface IAjaxJavaScriptObjectConverter
    {
        void ToJavaScript(ref StringBuilder sb, object obj);

        /// <summary>
        /// Converter can be used for multipal Types
        /// Returns the FullName of the types
        /// </summary>
        string[] TypesToConvert{get;}

    }

I've included StringCollection and DataTable as examples in the demo project. You must register a converter during the loading of the Page or UserControl - just like registering a Type for exporting.

            Ajax.JavaScriptHelper.RegisterConverter(new StringCollectionConverter());
            Ajax.JavaScriptHelper.RegisterConverter(new DataTableConverter());

Below is the converter for StringCollection - instred of recreating the object it converts it into an array of strings.

    public class StringCollectionConverter : Ajax.IAjaxJavaScriptObjectConverter
    {
        public StringCollectionConverter()
        {
        }
        #region IAjaxJavaScriptObjectConverter Members

        public void ToJavaScript(ref StringBuilder sb, object obj)
        {
            StringCollection coll = obj as StringCollection;

            if( coll == null )
            {
                return;
            }

            // output as array

            sb.Append('[');

            for(int i=0; i<coll.Count-1; i++)
            {
                Ajax.JavaScriptHelper.ObjectToJavaScript(ref sb, coll[i] );
                sb.Append(',');
            }
            if( coll.Count > 0 )
            {
                Ajax.JavaScriptHelper.ObjectToJavaScript(ref sb, coll[coll.Count-1]);
            }

            sb.Append(']');

        }


        public string[] TypesToConvert
        {
            get{return new string[]{"System.Collections.Specialized.StringCollection"};}
        }

        #endregion
    }

download AJAX for APS.Net

 |  | 
Wednesday, April 20, 2005 12:50:29 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]Trackback

download AJAX for APS.Net

I've written an AJAX library for ASP.Net applications. I got the idea from Michael Schwartz's AJAX Wrapper. It uses the same mechanism for including method signatures (inserting external .js files) but as he hasn't released the source code I'm not too sure how different/similar our implementations are but some of the known differences are:


Only uses one callback function per request (but not required, see next)


Supports synchronous calls as well as asynchronous class. If a callback function is not passed the call returns the request object.


Returns a single response object
   response.value (returned value/object from invoked method)
   response.error (exception/http error)
   response.request (the XmlHttpRequest)


Supports runtime checking of exposed Types - throws an exception if a method that is being exposed doesn't meet the criteria (public static method with parameters of simple types)

Using

Exposing Methods:

You can only expose public static methods with parameters of simple types such as int and bool. To expose the methods add the attribute

[Ajax.JavaScriptAccessableMethod]
public static void MethodName()


Including Method wrappers:

A JavaScript wrapper is generated for each exposed method which adds an extra parameter callback at the end.

public static int TestMethod(int a, int b)

becomes

function TestMethod(a, b, callback)

as youmay have noticed JavaScript being a scripting language doesn't have the rich type system that .Net has so overloaded methods won't work.

To include a type's wrappers register the type during the loading of the the Page or UserControl.

private void Page_Load(object sender, System.EventArgs e)
{
Ajax.MethodHelper.Register(typeof(TypeName));
}

Only the methods declared in the type will be exposed so there is no security problem with exposing base class methods.

Calling method from ClientSide:

Synchronously:

function test()
{
var response = TypeName.MethodName(parameter1, parameter2);
}

Asynchronously:


function test()
{
var response = TypeName.MethodName(parameter1, parameter2, callback);
}
function callback(response)
{
   
}

The response.error property will be null if everything went OK otherwise it will be an exception or "http" if there was a http error.

The response.value property will be the value/object of the methods return type. Objects only contain nonstatic public properties and fields.

function ajax_test_callback(response)
{
if( !response.error )
{
alert('Callback value:typeof = ' + typeof(response.value) + ', value = ' + response.value);
}
else if( response.error == 'http' )
{
alert('A http error occured: ' + request.status);
}
else
{
alert('An exception occured: ' + response.error);
}

}


If anyone has any feedback I really appreciate it.

download AJAX for APS.Net

 |  | 
Tuesday, April 19, 2005 10:47:49 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]Trackback
 Friday, April 15, 2005

Thanks to Clare Dillon Belfast is now also one of the locations for the "Visual C# and Windows Forms in Visual Studio 2005 Tour".

Mike Henderlight (Program Manager for the .Net Client Team) and Luca Bolognese (Program Manager for the C# team) will be giving high level talks about the new features and enhancements in C# 2.0, WinForms and Visual Studio 2005.

More information can be found on Clare's blog and you can also register for the event  which will be held at The Innovation Centre (Northern Ireland Science Park).

 

Friday, April 15, 2005 8:39:42 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]Trackback
 Wednesday, April 13, 2005
I've uploaded the files and slides from Mondays SQL Server talk onto the NIMTUG website.
Thursday, April 14, 2005 6:29:00 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]Trackback
 Tuesday, April 12, 2005

Tonight we had Microsoft's Robert Burke giving a talk on SQL Server 2005. Like the true .Net evangelist he is not even a forgotten USB cable or dodgy Virtual PC image could stop this guy giving a great talk. Rob covered most of the new feature but due to time constraints could only demo some of them, even so it gave us a good indication as developers of what to expect from Microsoft's next SQL Server release which should be with us shortly. Rob will be sending me the files/slides and related links from the talk shortly which I’ll be posting no the NIMTUG site, he also had a couple of interesting questions which stumped him but which he will be answering in his blog shortly.

 

We had a turnout of 33 and afterwards about 20+ of the talks attendees meet up afterwards for a drink and some food which was really good craic. Allot of good ideas came up with everyone getting together and talking which is something we'll hopefully be doing on a regular basis from now on.

If you have any follow up questions for Rob please post them on the NIMTUG forum

Tuesday, April 12, 2005 8:35:44 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]Trackback