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
 Friday, April 08, 2005

I signed up for MSDN Ireland Connections a while back and completely forgot about the free book I'd requested until it arrived this morning - now all I have to do is find some free time to read it.

Introducing Microsoft SQL Server 2005 for Developers

 

Friday, April 08, 2005 9:25:16 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0]Trackback

UPDATE: I since written my own AJAX library for ASP.Net

I first heard about AJAX a while ago but never had the time to check it out properly but then i came across Michael Schwartz's AJAX Wrapper for .Net and hacked around with it for a while. It's incredibly simple to use, you simple add the HttpHandler to you web.config, add a custom attribute on the methods you want to expose sand add another custom attribute to the classes you want to transport and write a bit of JavaScript. The control I wrote was a simple category selector but by using this technique I'm able to remove allot of postbacks from my web application. PostBacks seems harmless enough but should be used sparingly in large projects - especially is the pages are large and ViewState is used heavily. I don't think I'm going to be ditching winforms just yet like but I'll certainly be using AJAX where possible.

You can download the dll from Michael's blog

http://weblogs.asp.net/mschwarz/archive/2005/04/07/397504.aspx 

 

Friday, April 08, 2005 1:23:18 PM (GMT Daylight Time, UTC+01:00)  #    Comments [5]Trackback
 Thursday, March 31, 2005

I've updated the event page for Robert Burke's talk to include the summary and Robert's bio. You can register for the event and also post any pre-talk questions you may have which you want Robert to cover in his talk.

http://nimtug.org/11-april-2005.aspx 

Friday, April 01, 2005 1:07:43 AM (GMT Daylight Time, UTC+01:00)  #    Comments [2]Trackback