Archive for January, 2010

           We all may have use JQuery in our application to build rich UI. While working with JQuery today I found that JQuery is not working on some pages where I have user mootool scripts. I search on net and found a very descriptive solution at JQuery site.

           According to this article the reason for JQuery conflict is the use of $ function. mootool and prototype.js files have their own $ function. So when we use $() and try to access JQuery (as it is shorten form of jQuery()) browser is not able to resolve which $() function it has to use. To avoid JQuery conflict we have to use jQuery.noConflict() function.

           While you read JQuery site article you may have observe the order of java script files added to web page.  Read carefully and you find that you have to add other libraries first and then add JQuery library to page. If you change the order and add the JQuery library first, either mootool(or other library which you have included) or JQuery will not work.


Happy Programming !!!


Read Full Post »

       We all know what JSON is and how it helps to build rich application. Recently during free time I was playing with JSON. It is easy to pass simple data types between server and client however its bit tricky to work with complex data types.

        Consider that we have Student class with FirstName, LastName and City properties. You can pass array of Student object from client to server using JSON.stringify() method. See the code,

function LoadAjax() 
    var t = [
             { FirstName: "Chirag", LastName: "Darji",City:"Ahmedabad" }, 
             { FirstName: "Chirag", LastName: "Darji",City:"Ahmedabad" } 
                { values: JSON.stringify(t) }

Fig – (1) Passing complex data type using JSON

          Here we are passing array of two customer object from client to server using JSON. I have used JQUERY load method which use POST method to send the data to requested page. You can convert this parameter to Student class using following code,

var json = new DataContractJsonSerializer(typeof(List<Student>));
var stream = new MemoryStream(Encoding.UTF8.GetBytes(Request.Form["values"]));
List<Student> lstStudents = (List<Student>)json.ReadObject(stream);

Fig – (2) Generating Lsit<Student> from JSON data type


Happy Programming!!!

Read Full Post »