<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Rajeesh&#039;s Blog &#187; JavaScript</title>
	<atom:link href="http://www.rajeeshcv.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rajeeshcv.com</link>
	<description>Sharing my knowledge</description>
	<lastBuildDate>Sun, 18 Jul 2010 06:09:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Asp.Net MVC &#8211; Fluent Html helper for FlexiGrid</title>
		<link>http://www.rajeeshcv.com/2010/04/asp-net-mvc-fluent-html-helper-for-flexigrid/</link>
		<comments>http://www.rajeeshcv.com/2010/04/asp-net-mvc-fluent-html-helper-for-flexigrid/#comments</comments>
		<pubDate>Sun, 18 Apr 2010 10:31:00 +0000</pubDate>
		<dc:creator>Rajeesh</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://www.rajeeshcv.com/2010/04/asp-net-mvc-fluent-html-helper-for-flexigrid/</guid>
		<description><![CDATA[There are so many free JQuery Grid plugins out there, in that I liked FlexiGrid just because of it’s look and style. In order to use it in your MVC application you may have to put the Javascript code into your view, which requires the property names of your model in order to generates the [...]]]></description>
			<content:encoded><![CDATA[<p>There are so many free JQuery Grid plugins out there, in that I liked <a title="FlexiGrid" href="http://flexigrid.info/" target="_blank">FlexiGrid</a> just because of it’s look and style. In order to use it in your MVC application you may have to put the Javascript code into your view, which requires the property names of your model in order to generates the Grid columns as well the search options etc… as everybody knows when you deal with hard coded string as the property names in any code, it is error prone. </p>
<p>In order to avoid this problem I thought of creating a html extension which is tightly coupled with your data that is going to bound to the Grid. Which helps the developer from writing any javascript codes(I know those who hates(not me! <img src='http://www.rajeeshcv.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ) writing Javascript code like this extension).</p>
<p>This project has been uploaded to &#8211; <a href="http://code.google.com/p/mvc-fluent-jquery-plugin-controls/">http://code.google.com/p/mvc-fluent-jquery-plugin-controls/</a>. You could find more details from there.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rajeeshcv.com/2010/04/asp-net-mvc-fluent-html-helper-for-flexigrid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JQueryUI Datepicker in ASP.Net MVC</title>
		<link>http://www.rajeeshcv.com/2010/02/jqueryui-datepicker-in-asp-net-mvc/</link>
		<comments>http://www.rajeeshcv.com/2010/02/jqueryui-datepicker-in-asp-net-mvc/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 02:39:00 +0000</pubDate>
		<dc:creator>Rajeesh</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[CodeProject]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Datepicker]]></category>
		<category><![CDATA[JQueryUI]]></category>

		<guid isPermaLink="false">http://www.rajeeshcv.com/2010/02/jqueryui-datepicker-in-asp-net-mvc/</guid>
		<description><![CDATA[Technocrati code : M2U2PWSNTKW3 
Datepicker is nice and cool plugin for displaying the calendar with ease. It is very easy to use JQuery plugin, it comes as part of JQueryUI library, so if you want to use this – first download JQueryUI from http://jqueryui.com/download and also download JQuery(http://docs.jquery.com/Downloading_jQuery) if you haven’t done yet.
&#160;
For e.g. if [...]]]></description>
			<content:encoded><![CDATA[<p>Technocrati code : M2U2PWSNTKW3 </p>
<p>Datepicker is nice and cool plugin for displaying the calendar with ease. It is very easy to use JQuery plugin, it comes as part of JQueryUI library, so if you want to use this – first download JQueryUI from <a href="http://jqueryui.com/download">http://jqueryui.com/download</a> and also download JQuery(<a title="http://docs.jquery.com/Downloading_jQuery" href="http://docs.jquery.com/Downloading_jQuery">http://docs.jquery.com/Downloading_jQuery</a>) if you haven’t done yet.</p>
<p><a href="http://www.rajeeshcv.com/wp-content/uploads/2010/02/image.png" rel="lightbox"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="230" alt="image" src="http://www.rajeeshcv.com/wp-content/uploads/2010/02/image_thumb.png" width="270" border="0" /></a>&#160;</p>
<p>For e.g. if you have a form like one below</p>
<pre class="brush: xml;">&lt;% using(Html.BeginForm()){%&gt;
  &lt;fieldset&gt;
    &lt;legend&gt;Event Information&lt;/legend&gt;
     &lt;p&gt;
        &lt;label for=&quot;EventName&quot;&gt;Event Name:&lt;/label&gt;
        &lt;%= Html.TextBox(&quot;EventName&quot;)%&gt;
            &lt;/p&gt;
            &lt;p&gt;
            &lt;label for=&quot;StartDate&quot;&gt;Start Date:&lt;/label&gt;
            &lt;%= Html.TextBox(&quot;StartDate&quot;)%&gt;
            &lt;/p&gt;
            &lt;p&gt;
            &lt;label for=&quot;EndDate&quot;&gt;End Date:&lt;/label&gt;
            &lt;%= Html.TextBox(&quot;EndDate&quot;)%&gt;
            &lt;/p&gt;
            &lt;p&gt;
                &lt;input type=&quot;submit&quot; value=&quot;Save&quot; /&gt;
            &lt;/p&gt;
  &lt;/fieldset&gt;
&lt;% }%&gt;</pre>
<p>and you want to attach datepicker to “StartDate” and “EndDate” input fields,</p>
</p>
<p><span id="more-162"></span></p>
<p>what you needs to do is call the datepicker function on the these input field selector like below.</p>
<pre class="brush: js;">&lt;script language=&quot;javascript&quot;&gt;
    $(document).ready(function() {
    $('#StartDate').datepicker();
    $('#EndDate').datepicker();
    });
&lt;/script&gt;</pre>
<p>This works fine as we expected <img src='http://www.rajeeshcv.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong><u>Difference in Date format patterns</u></strong></p>
<p>Consider a scenario where your MVC application supports localization, then the selected date displayed in the input fields also should display the in the same date format of the current culture(This format could be custom one or default one). This leads to you another issue – Datepicker plugin given by the JQueryUI supports different date formats, but it is different from one that is available in .NET. For e.g. in order to display a long day name (“Thursday”) .NET uses “<strong>dddd</strong>” its equivalent in Datepicker is “<strong>DD”</strong>.</p>
<p>In order to solve this disparity between the .NET world and Datepicker world, I have created a html helper function, which could generate the Datepicker format from a .Net date format.</p>
<pre class="brush: csharp;">/// &lt;summary&gt;
/// JQuery UI DatePicker helper.
/// &lt;/summary&gt;
public static class JQueryUIDatePickerHelper
{
    /// &lt;summary&gt;
    /// Converts the .net supported date format current culture format into JQuery Datepicker format.
    /// &lt;/summary&gt;
    /// &lt;param name=&quot;html&quot;&gt;HtmlHelper object.&lt;/param&gt;
    /// &lt;returns&gt;Format string that supported in JQuery Datepicker.&lt;/returns&gt;
    public static string ConvertDateFormat(this HtmlHelper html)
    {
        return ConvertDateFormat(html, Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern);
    }

    /// &lt;summary&gt;
    /// Converts the .net supported date format current culture format into JQuery Datepicker format.
    /// &lt;/summary&gt;
    /// &lt;param name=&quot;html&quot;&gt;HtmlHelper object.&lt;/param&gt;
    /// &lt;param name=&quot;format&quot;&gt;Date format supported by .NET.&lt;/param&gt;
    /// &lt;returns&gt;Format string that supported in JQuery Datepicker.&lt;/returns&gt;
    public static string ConvertDateFormat(this HtmlHelper html, string format)
    {
        /*
         *  Date used in this comment : 5th - Nov - 2009 (Thursday)
         *
         *  .NET    JQueryUI        Output      Comment
         *  --------------------------------------------------------------
         *  d       d               5           day of month(No leading zero)
         *  dd      dd              05          day of month(two digit)
         *  ddd     D               Thu         day short name
         *  dddd    DD              Thursday    day long name
         *  M       m               11          month of year(No leading zero)
         *  MM      mm              11          month of year(two digit)
         *  MMM     M               Nov         month name short
         *  MMMM    MM              November    month name long.
         *  yy      y               09          Year(two digit)
         *  yyyy    yy              2009        Year(four digit)             *
         */

        string currentFormat = format;

        // Convert the date
        currentFormat = currentFormat.Replace(&quot;dddd&quot;, &quot;DD&quot;);
        currentFormat = currentFormat.Replace(&quot;ddd&quot;, &quot;D&quot;);

        // Convert month
        if (currentFormat.Contains(&quot;MMMM&quot;))
        {
            currentFormat = currentFormat.Replace(&quot;MMMM&quot;, &quot;MM&quot;);
        }
        else if (currentFormat.Contains(&quot;MMM&quot;))
        {
            currentFormat = currentFormat.Replace(&quot;MMM&quot;, &quot;M&quot;);
        }
        else if (currentFormat.Contains(&quot;MM&quot;))
        {
            currentFormat = currentFormat.Replace(&quot;MM&quot;, &quot;mm&quot;);
        }
        else
        {
            currentFormat = currentFormat.Replace(&quot;M&quot;, &quot;m&quot;);
        }

        // Convert year
        currentFormat = currentFormat.Contains(&quot;yyyy&quot;) ? currentFormat.Replace(&quot;yyyy&quot;, &quot;yy&quot;) : currentFormat.Replace(&quot;yy&quot;, &quot;y&quot;);

        return currentFormat;
    }
}</pre>
<p>So how we could make use this helper method, just replace the datepicker initialization code we have written earlier with this</p>
<pre class="brush: xml;">&lt;script language=&quot;javascript&quot;&gt;
    $(document).ready(function() {
    $('#StartDate').datepicker({ dateFormat: '&lt;%= Html.ConvertDateFormat() %&gt;' });
    $('#EndDate').datepicker({ dateFormat: '&lt;%= Html.ConvertDateFormat() %&gt;' });
    });
&lt;/script&gt;</pre>
<p>Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rajeeshcv.com/2010/02/jqueryui-datepicker-in-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inline editing using JQuery</title>
		<link>http://www.rajeeshcv.com/2009/06/inline-editing-using-jquery/</link>
		<comments>http://www.rajeeshcv.com/2009/06/inline-editing-using-jquery/#comments</comments>
		<pubDate>Fri, 26 Jun 2009 00:29:21 +0000</pubDate>
		<dc:creator>Rajeesh</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.rajeeshcv.com/2008/07/inline-editing-using-jquery/</guid>
		<description><![CDATA[A post I forgot to publish which I wrote an year back
Here I wanted to show you the flexibility of JQuery.
Below is a HTML code that generates a grid with two rows and ten columns.
&#60;div&#62;

&#60;div&#62;1&#60;/div&#62;
&#60;div&#62;2&#60;/div&#62;
&#60;div&#62;3&#60;/div&#62;
&#60;div&#62;4&#60;/div&#62;
&#60;div&#62;5&#60;/div&#62;
&#60;div&#62;6&#60;/div&#62;
&#60;div&#62;7&#60;/div&#62;
&#60;div&#62;8&#60;/div&#62;
&#60;div&#62;9&#60;/div&#62;
&#60;div&#62;10&#60;/div&#62;

&#60;div&#62;11&#60;/div&#62;
&#60;div&#62;12&#60;/div&#62;
&#60;div&#62;13&#60;/div&#62;
&#60;div&#62;14&#60;/div&#62;
&#60;div&#62;15&#60;/div&#62;
&#60;div&#62;16&#60;/div&#62;
&#60;div&#62;17&#60;/div&#62;
&#60;div&#62;18&#60;/div&#62;
&#60;div&#62;19&#60;/div&#62;
&#60;div&#62;20&#60;/div&#62;

&#60;/div&#62;
When the user double clicks on any of the cell, he can edit that content. The cell value get updated when [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>A post I forgot to publish which I wrote an year back</p></blockquote>
<p>Here I wanted to show you the flexibility of JQuery.</p>
<p>Below is a HTML code that generates a grid with two rows and ten columns.<span id="more-48"></span></p>
<pre class="HTML" name="code">&lt;div&gt;

&lt;div&gt;1&lt;/div&gt;
&lt;div&gt;2&lt;/div&gt;
&lt;div&gt;3&lt;/div&gt;
&lt;div&gt;4&lt;/div&gt;
&lt;div&gt;5&lt;/div&gt;
&lt;div&gt;6&lt;/div&gt;
&lt;div&gt;7&lt;/div&gt;
&lt;div&gt;8&lt;/div&gt;
&lt;div&gt;9&lt;/div&gt;
&lt;div&gt;10&lt;/div&gt;

&lt;div&gt;11&lt;/div&gt;
&lt;div&gt;12&lt;/div&gt;
&lt;div&gt;13&lt;/div&gt;
&lt;div&gt;14&lt;/div&gt;
&lt;div&gt;15&lt;/div&gt;
&lt;div&gt;16&lt;/div&gt;
&lt;div&gt;17&lt;/div&gt;
&lt;div&gt;18&lt;/div&gt;
&lt;div&gt;19&lt;/div&gt;
&lt;div&gt;20&lt;/div&gt;

&lt;/div&gt;</pre>
<p>When the user double clicks on any of the cell, he can edit that content. The cell value get updated when user double clicks on any other cell.</p>
<p><a href="http://labs.rajeeshcv.com/inlineediting/index.html" target="_blank">Visit here</a> to see the demo.</p>
<pre class="jscript"  name="code">$(document).ready(function(){
$("div.column").dblclick(function(){ 

var content = $(this).text();
var width = $(this).width() -1;
var height = $(this).height() - 4;

var $editbox = $("&lt;input type='text'" +
"style='width:" + width + ";" +
"height:" + height + ";" +
"border:none" +
"' value='" +  content + "' /&gt;"); 

$(this).empty();
$(this).prepend($editbox);
$editbox.focus();
$editbox.select();

$($editbox).bind("blur",function(){                     

content = $(this).val();
var parent = $(this).parent();
parent.html(content); 

});

});

});</pre>
<p>The above code does all the trick.</p>
<p>First we hook the &#8220;Double Click&#8221; event to all the DIV with class name &#8220;column&#8221; using this</p>
<p>$(&#8220;div.column&#8221;).dblclick(function(){&#8230;});</p>
<p>Inside that, we dynamically add a textbox inside the DIV and set its text value as the HTML content of the parent DIV. And also we bind the &#8220;blur&#8221; event of this texbox to a function, so that whenever the focus leaves from the textbox, that function is called.</p>
<pre class="jscript"  name="code">$($editbox).bind("blur",function(){

content = $(this).val();
var parent = $(this).parent();
parent.html(content);

});</pre>
<p>inside that function, we set the HTML content of the DIV with the Textbox value.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rajeeshcv.com/2009/06/inline-editing-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET AJAX &#8211; Passing JSON object from client to server</title>
		<link>http://www.rajeeshcv.com/2008/10/aspnet-ajax-passing-json-object-from-client-to-server/</link>
		<comments>http://www.rajeeshcv.com/2008/10/aspnet-ajax-passing-json-object-from-client-to-server/#comments</comments>
		<pubDate>Mon, 27 Oct 2008 18:39:15 +0000</pubDate>
		<dc:creator>Rajeesh</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.rajeeshcv.com/2008/10/aspnet-ajax-passing-json-object-from-client-to-server/</guid>
		<description><![CDATA[Passing JSON object from client to server]]></description>
			<content:encoded><![CDATA[<ol>
<li><a title="calling server side methods from client side" href="http://www.rajeeshcv.com/2008/10/aspnet-ajax-calling-server-side-methods-from-client-side/" target="_blank">Part 1- Calling server side methods from client side</a> </li>
</ol>
<p>Read the Part 1 of this tutorial if you don&#8217;t know how to call server side methods directly from client side.</p>
<p>In this post, I will explain how to pass data from client to server in JSON format.</p>
<p>Microsoft AJAX client library has built-in methods which helps in serializing and de-serializing JSON. The methods are defined in &quot;<strong>Sys.Serialization.JavaScriptSerializer</strong>&quot; class. In server side we have &quot;<strong>JavaScriptSerializer</strong>&quot;that will help you out to do the JSON serialization and de-serialization.</p>
<p><span id="more-78"></span></p>
<p>With the help of these two classes, we can easily do the data transfer. Suppose you have class called <strong>&quot;Customer&quot;</strong> in server side, which looks like this</p>
<pre class="c-sharp" name="code">
using System;

namespace ServerClientInteration
{
    [Serializable]
    public class Customer
    {
        public int ID { get; set; }

        public string Name { get; set; }

        public string Address { get; set; }
    }
}</pre>
<p>This is our payload for this example, we are going to move this object from server to client and vice versa. For that I have exposed two static methods on the server side; one is for retrieving the customer details and the other is for updating the customer.</p>
<pre class="c-sharp" name="code">
  public partial class _Default : System.Web.UI.Page
    {
        private static Customer customer = null;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (customer == null)
            {
                customer = new Customer();
                customer.ID = 1;
                customer.Name = &quot;microsoft&quot;;
                customer.Address = &quot;www.microsoft.com&quot;;
            }

        }

        [WebMethod]
        [ScriptMethod(UseHttpGet=true)]
        public static string GetTime()
        {
            return DateTime.Now.ToLongTimeString();
        }

        [WebMethod]
        [ScriptMethod(UseHttpGet = true)]
        public static string GetCustomer()
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            return serializer.Serialize(customer);
        }

        [WebMethod]
        [ScriptMethod]
        public static string UpdateCustomer(string jsonCustomer)
        {
            try
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                Customer cust = serializer.Deserialize<customer>(jsonCustomer);
                customer.ID = cust.ID;
                customer.Name = cust.Name;
                customer.Address = cust.Address;

                return &quot;Updated&quot;;
            }
            catch(Exception Exception)
            {

            }

            return &quot;Error occured while updating&quot;;
        }
    }</pre>
<p>In the above code, you can see &quot;<strong>GetCustomer</strong>&quot; and &quot;<strong>UpdateCustomer</strong>&quot; methods. &quot;<strong>GetCustomer</strong>&quot; will serialize the static customer object and return it as JSON string; &quot;<strong>UpdateCustomer</strong>&quot; method accepts JSON string as input and that string is de-serialized in to a customer object and the static customer variable is updated with the new values. &quot;<strong>UpdateCustomer</strong>&quot; will return status message after the update.</p>
<p>Usually, we persist the customer in DB or some other states, but here for simplicity I have used a static variable which will simulate the persistence.</p>
<p>Now we need to call this from the client-side, for that I have two hyperlinks; one will get the customer from the server and other send the customer to the server.</p>
<p>Here is how the HTML looks like</p>
<pre class="html" name="code">
&lt;head runat=&quot;server&quot;&gt;
&lt;title&gt;Untitled Page&lt;/title&gt;
&lt;style type=&quot;text/css&quot;&gt; 

#result
{
width: 250px;
height: 300px;
overflow: auto;
border:1px solid #00d;
} 

&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;
&lt;asp:ScriptManager ID=&quot;ScriptManager1&quot; runat=&quot;server&quot; EnablePageMethods=&quot;true&quot;&gt;
&lt;/asp:ScriptManager&gt;
&lt;div&gt;
&lt;a href=&quot;javascript:callServerMethod()&quot; &gt;Call Server method&lt;/a&gt;
&lt;hr /&gt;
&lt;a href=&quot;javascript:getCustomer()&quot; &gt;Get Customer&lt;/a&gt;
&lt;div id=&quot;result&quot;&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;div&gt;
ID : &lt;input type=&quot;text&quot; id=&quot;custID&quot; /&gt;&lt;br /&gt;
Name : &lt;input type=&quot;text&quot; id=&quot;custName&quot; /&gt;&lt;br /&gt;
Adress : &lt;input type=&quot;text&quot; id=&quot;custAdd&quot; /&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;a href=&quot;javascript:updateCustomer()&quot; &gt;Update customer&lt;/a&gt;&lt;br /&gt; 

&lt;/div&gt;
&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;
//&lt;![CDATA[ 

function callServerMethod()
{
PageMethods.GetTime(callBackMethod);
} 

function callBackMethod(result)
{
alert(result);
} 

function getCustomer()
{
PageMethods.GetCustomer(callBackGetCustomer);
} 

function callBackGetCustomer(result)
{
var customer = Sys.Serialization.JavaScriptSerializer.deserialize(result);
var content = &quot;&lt;br /&gt;ID :&quot; +  customer.ID + &quot;&lt;br /&gt;&quot; + &quot;Name : &quot; + customer.Name + &quot;&lt;br /&gt;&quot; + &quot;Address : &quot; + customer.Address;
$get(&quot;result&quot;).innerHTML += content;
} 

var clientCustomer = function(id,name,add){
this.ID = id;
this.Name = name;
this.Address = add;
}; 

function updateCustomer()
{
var id = $get(&quot;custID&quot;).value;
var name = $get(&quot;custName&quot;).value;
var address = $get(&quot;custAdd&quot;).value; 

var customer = new clientCustomer(id,name,address);
var serializedCustomer = Sys.Serialization.JavaScriptSerializer.serialize(customer);
PageMethods.UpdateCustomer(serializedCustomer,callBackUpdateCustomer);
} 

function callBackUpdateCustomer(result)
{
alert(result);
} 

//]]&gt;
&lt;/script&gt;
&lt;/form&gt;
&lt;/body&gt;</pre>
<p>I think the above code is self explanatory, let me know if you have any difficulty in understanding this.</p>
<p>Hope this will gave some idea about passing JSON between client and server. I have uploaded the source code in my server and you can get it from here &#8211; <a href="http://www.rajeeshcv.com/download/ServerClientInteration.zip">http://www.rajeeshcv.com/download/ServerClientInteration.zip</a></p>
<div class="wlWriterSmartContent" id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:bd873e8b-d1f1-463c-a8ed-d3c0733e6590" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://www.dotnetkicks.com/kick/?url=http://www.rajeeshcv.com/2008/10/aspnet-ajax-passing-json-object-from-client-to-server/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://www.rajeeshcv.com/2008/10/aspnet-ajax-passing-json-object-from-client-to-server/" border="0" alt="kick it on DotNetKicks.com" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.rajeeshcv.com/2008/10/aspnet-ajax-passing-json-object-from-client-to-server/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>ASP.NET AJAX &#8211; Calling server side methods from client side</title>
		<link>http://www.rajeeshcv.com/2008/10/aspnet-ajax-calling-server-side-methods-from-client-side/</link>
		<comments>http://www.rajeeshcv.com/2008/10/aspnet-ajax-calling-server-side-methods-from-client-side/#comments</comments>
		<pubDate>Fri, 24 Oct 2008 19:13:52 +0000</pubDate>
		<dc:creator>Rajeesh</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Ajax]]></category>

		<guid isPermaLink="false">http://www.rajeeshcv.com/2008/10/aspnet-ajax-calling-server-side-methods-from-client-side/</guid>
		<description><![CDATA[Calling server side methods from client side - an asp.net AJAX technique]]></description>
			<content:encoded><![CDATA[<p>ASP.net AJAX has got nice bridging between your server side and client side technologies. Using the ASP.net AJAX you can easily call a method in a page. The restriction here is that, the methods your are trying to call should be static and public.</p>
<p>This feature(calling server side static method) is not enabled by default, so you have to manually enable this and it is very very simple; just set the &quot;<strong>EnablePageMethods</strong>&quot; property of the &quot;<strong>ScriptManager</strong>&quot; to <strong>true</strong> like this</p>
<p><span id="more-77"></span></p>
<p>&#160;</p>
<p>&#160;</p>
<p>&#160;</p>
<p>&#160;</p>
<pre class="html" name="code">&lt;asp:scriptmanager id=&quot;ScriptManager1&quot; runat=&quot;server&quot; enablepagemethods=&quot;true&quot;&gt;&#160;&#160;&#160;&#160;&#160; &lt;/asp:scriptmanager&gt;</pre>
</p>
<p>After this, create a public static method in your asp.net page and decorate it with WebMethod(System.Web.Services.dll) and ScriptMethod(System.Web.Extensions.dll) attributes. For example I have created a static method called &quot;<strong>GetTime()</strong>&quot; which returns current time as string.</p>
</p>
<pre class="c-sharp" name="code">
public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        [WebMethod]
        [ScriptMethod]
        public static string GetTime()
        {
            return DateTime.Now.ToLongTimeString();
        }
    }  </pre>
</p>
<p>Now you have configured everything correctly and I will show you how to call this method from the client side.</p>
<p>Earlier you have set the &quot;<strong>EnablePageMethods</strong>&quot; property of &quot;<strong>ScriptManager</strong>&quot; to <strong>true</strong>, as a result of that a new object called &quot;<strong>PageMethods</strong>&quot; is created by the <strong>ScriptManager</strong> when the page is rendered. This object has all the public static methods in that page. So that you call the server side method like <strong>PageMethods.[ServerSideMethodName]</strong>. When calling this methods from client side you have to provide a callback function because here all the call scriptmanager made will be asynchronous, and this callback method will get the returned result.</p>
<p>Below is the sample code </p>
</p>
<pre class="javascript" name="code">
	function callServerMethod()
        {
            PageMethods.GetTime(callBackMethod);
        }

        function callBackMethod(result)
        {
            alert(result);
        }</pre>
<p>Complete aspx page looks like this </p>
<pre class="html" name="code">
&lt;body&gt;&#160;&#160;&#160;&#160; &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;&#160;&#160;&#160;&#160;&#160;&#160; &lt;asp:ScriptManager ID=&quot;ScriptManager1&quot; runat=&quot;server&quot; EnablePageMethods=&quot;true&quot;&gt;&#160;&#160;&#160;&#160;&#160; &lt;/asp:ScriptManager&gt;&#160;&#160;&#160;&#160;&#160; &lt;div&gt;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;a href=&quot;javascript:callServerMethod()&quot; &gt;Call Server method&lt;/a&gt;&#160;&#160;&#160;&#160;&#160; &lt;/div&gt;&#160;&#160;&#160;&#160;&#160; &lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;&#160;&#160;&#160;&#160;&#160; //&lt;![CDATA[&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; function callServerMethod()&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; PageMethods.GetTime(callBackMethod);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; function callBackMethod(result)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; alert(result);&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }&#160;&#160;&#160;&#160;&#160; //]]&gt;&#160;&#160;&#160;&#160;&#160; &lt;/script&gt;&#160;&#160;&#160;&#160;&#160; &lt;/form&gt;
&lt;/body&gt;</pre>
</p>
<p><strong><u>Extra bits</u></strong></p>
<p>In the above code you can see that I have placed link, when user click on that link a message is shown with the server time. So behind an asynchronous request is send to the server in this format (<strong><a href="http://[sitename]/[MethodName">http://[sitename]/[MethodName</a></strong><strong>]</strong>). Server in turn returns the result as JSON back to the client. Here is a screen shot from the firebug</p>
<p><a href="http://www.rajeeshcv.com/wp-content/uploads/2008/10/image.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="384" alt="image" src="http://www.rajeeshcv.com/wp-content/uploads/2008/10/image-thumb.png" width="422" border="0" /></a> </p>
<p><a href="http://www.rajeeshcv.com/wp-content/uploads/2008/10/image1.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="121" alt="image" src="http://www.rajeeshcv.com/wp-content/uploads/2008/10/image-thumb1.png" width="342" border="0" /></a></p>
<p>There is optimization we have do here &#8211; you can see that, by default the request is a <strong>POST</strong> request, but in our case a POST request is heavy because we could have achieved the same using a <strong>GET</strong> request ( <a href="http://www.cs.tut.fi/~jkorpela/forms/methods.html" target="_blank">Difference between POST and GET</a> ). </p>
<p></p>
<p>In order to change this request in to a <strong>GET</strong> request, we need to do a minor tweaking in the server side, set &quot;<strong>UseHttpGet=true</strong>&quot; parameter for the &quot;<strong>ScriptMethod</strong>&quot; attribute.</p>
<pre class="c-sharp" name="code">
	[WebMethod]
        [ScriptMethod(UseHttpGet=true)]
        public static string GetTime()
        {
            return DateTime.Now.ToLongTimeString();
        }</pre>
<p>After this you can see that, request is changed to a <strong>GET </strong>request</p>
<p><a href="http://www.rajeeshcv.com/wp-content/uploads/2008/10/image2.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="355" alt="image" src="http://www.rajeeshcv.com/wp-content/uploads/2008/10/image-thumb2.png" width="385" border="0" /></a></p>
<div class="wlWriterSmartContent" id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:9c3bb28b-7aaf-4bce-a9b0-a850fec8227a" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://www.dotnetkicks.com/kick/?url=http://www.rajeeshcv.com/2008/10/aspnet-ajax-calling-server-side-methods-from-client-side/"><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://www.rajeeshcv.com/2008/10/aspnet-ajax-calling-server-side-methods-from-client-side/" border="0" alt="kick it on DotNetKicks.com" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.rajeeshcv.com/2008/10/aspnet-ajax-calling-server-side-methods-from-client-side/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JQuery in asp.net</title>
		<link>http://www.rajeeshcv.com/2008/09/jquery-in-aspnet/</link>
		<comments>http://www.rajeeshcv.com/2008/09/jquery-in-aspnet/#comments</comments>
		<pubDate>Mon, 29 Sep 2008 19:17:47 +0000</pubDate>
		<dc:creator>Rajeesh</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.rajeeshcv.com/?p=59</guid>
		<description><![CDATA[A good news for the  JQuery lovers like me; Scott Guthrie anounced that JQuery will be shipped along with Visual Studio and Microsoft is planning to use this excellent javascript library in their future control release.
]]></description>
			<content:encoded><![CDATA[<p>A good news for the  <a href="http://www.jquery.com" target="_blank">JQuery</a> lovers like me; <a href="http://weblogs.asp.net/scottgu" target="_blank"><span style="font-family: Arial; font-size: x-small;">Scott Guthrie</span></a> anounced that JQuery will be shipped along with Visual Studio and Microsoft is planning to use this excellent javascript library in their future control release.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rajeeshcv.com/2008/09/jquery-in-aspnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LayoutManager  &#8211; custom control for asp.net</title>
		<link>http://www.rajeeshcv.com/2008/09/layoutmanager-custom-control-for-aspnet/</link>
		<comments>http://www.rajeeshcv.com/2008/09/layoutmanager-custom-control-for-aspnet/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 17:52:36 +0000</pubDate>
		<dc:creator>Rajeesh</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Custom Control]]></category>
		<category><![CDATA[LayoutManager]]></category>

		<guid isPermaLink="false">http://www.rajeeshcv.com/?p=56</guid>
		<description><![CDATA[I have created an asp.net custom control on top of my JQuery Plugin, with good design time support. So that you don’t need to write any lines code.
Get more details from here http://code.google.com/p/weblayoutmanager/
Please let me know your suggestions
]]></description>
			<content:encoded><![CDATA[<p>I have created an asp.net custom control on top of my JQuery Plugin, with good design time support. So that you don’t need to write any lines code.</p>
<p>Get more details from here <a href="http://code.google.com/p/weblayoutmanager/" target="_blank">http://code.google.com/p/weblayoutmanager/</a></p>
<p>Please let me know your suggestions</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rajeeshcv.com/2008/09/layoutmanager-custom-control-for-aspnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LayoutManger plugin &#8211; documenation and demos</title>
		<link>http://www.rajeeshcv.com/2008/09/layoutmanger-plugin-documenation-and-demos/</link>
		<comments>http://www.rajeeshcv.com/2008/09/layoutmanger-plugin-documenation-and-demos/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 19:02:36 +0000</pubDate>
		<dc:creator>Rajeesh</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[JQuery Plugin]]></category>

		<guid isPermaLink="false">http://www.rajeeshcv.com/?p=55</guid>
		<description><![CDATA[I have created a separate page for this plugin with documentation and demos.
Please go to  http://www.rajeeshcv.com/projects/layoutmanager-jquery-plugin/ to read more about this plugin and how to use it.
]]></description>
			<content:encoded><![CDATA[<p>I have created a separate page for this plugin with documentation and demos.</p>
<p>Please go to  <a href="http://www.rajeeshcv.com/projects/layoutmanager-jquery-plugin/">http://www.rajeeshcv.com/projects/layoutmanager-jquery-plugin/</a> to read more about this plugin and how to use it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rajeeshcv.com/2008/09/layoutmanger-plugin-documenation-and-demos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Docking Layout Manager &#8211; JQuery Plugin Released</title>
		<link>http://www.rajeeshcv.com/2008/08/docking-layout-manager-jquery-plugin-released/</link>
		<comments>http://www.rajeeshcv.com/2008/08/docking-layout-manager-jquery-plugin-released/#comments</comments>
		<pubDate>Tue, 19 Aug 2008 08:37:16 +0000</pubDate>
		<dc:creator>Rajeesh</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.rajeeshcv.com/2008/08/docking-layout-manager-jquery-plugin-released/</guid>
		<description><![CDATA[For more details visit here &#8211; http://plugins.jquery.com/project/layoutmanager
Demo and source is available here &#8211; http://labs.rajeeshcv.com/layoutmanager/default.html
]]></description>
			<content:encoded><![CDATA[<p>For more details visit here &#8211; <a href="http://plugins.jquery.com/project/layoutmanager" target="_blank">http://plugins.jquery.com/project/layoutmanager</a></p>
<p>Demo and source is available here &#8211; <a href="http://labs.rajeeshcv.com/layoutmanager/default.html" target="_blank">http://labs.rajeeshcv.com/layoutmanager/default.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rajeeshcv.com/2008/08/docking-layout-manager-jquery-plugin-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spell checker in JavaScript</title>
		<link>http://www.rajeeshcv.com/2008/04/spell-checker-in-javascript/</link>
		<comments>http://www.rajeeshcv.com/2008/04/spell-checker-in-javascript/#comments</comments>
		<pubDate>Fri, 25 Apr 2008 17:02:26 +0000</pubDate>
		<dc:creator>Rajeesh</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.rajeeshcv.com/2008/04/spell-checker-in-javascript/</guid>
		<description><![CDATA[I was looking for a spell checker in javascript, pure javascript so that I could use it in offline mode. When I googled I could find many spell checkers in javascript, but all of them are using web services to get the dictionary. Those code won&#8217;t work in offline mode , hope somebody could guide [...]]]></description>
			<content:encoded><![CDATA[<p>I was looking for a spell checker in javascript, pure javascript so that I could use it in offline mode. When I googled I could find many spell checkers in javascript, but all of them are using web services to get the dictionary. Those code won&#8217;t work in offline mode , hope somebody could guide me in finding the spell checker I am looking for.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rajeeshcv.com/2008/04/spell-checker-in-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
