Click here to Skip to main content
13,087,235 members (55,414 online)
Click here to Skip to main content


33 bookmarked
Posted 13 Jun 2011

Simple JSON Handler for ASP.NET 2.0 to Implement AJAX Functionality

, 30 Jun 2011
Simple JSON handler for ASP.NET 2.0 to implement AJAX functionality
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SampleAjax.aspx.cs" Inherits="SampleJSONWeb.SampleAjax" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >

<head id="Head1" runat="server">
    <title>Untitled Page</title>
    <link type="text/css" href='Scripts/jquery-ui-1.8.11.custom.css' rel="stylesheet" />
    <script type="text/javascript" src='<%= this.ResolveUrl("~/Scripts/jquery-1.5.2.min.js")%>' ></script>
    <script type="text/javascript" src='<%= this.ResolveUrl("~/Scripts/jquery-ui-1.8.11.custom.min.js")%>' ></script>
    <script type="text/javascript" src='<%= this.ResolveUrl("~/Scripts/sample_ajax.js")%>' ></script>

    <form id="form1" runat="server">
     <script type="text/javascript">
     <% if (SampleJSONWeb.ConfigurationData.DebugMode){ %>
            <%} %>
    $(document).ready(function () 
        $("#<%= customerDropDown.ClientID %>").change(function () 
                var customerTypeId = $('#<%= customerDropDown.ClientID %>').val();
                ajax.get('<%= this.ResolveUrl("~/LoadCustomerDescriptions.ashx")%>',
                    { 'customerTypeId': customerTypeId },
                        function (response) 
                            $('#<%= customerDescriptionDropDown.ClientID %> option').remove();
                            for (var i = 0; i < response.Data.length; i++) 
                                $('#<%= customerDescriptionDropDown.ClientID %>').append(getOptionString(response.Data[i]));
        function getOptionString(dataElement)
          return "<option value='"+dataElement.Id+"' >"+dataElement.Name+"</option>";


        <asp:DropDownList ID="customerDropDown" runat="server" Width="200px"  >
        <img id="CustomerDescriptionsLoader" style="display:none" src="<%= this.ResolveUrl("~/Images/ajax-loader.gif") %>" alt="loading" />
        Customer Description:
        <asp:DropDownList ID="customerDescriptionDropDown" runat="server" Width="200px" >

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Pubudu Kasakara
Singapore Singapore
Pubudu Kasakara is working as Solution Architect in Singapore. He has more than 11 years of professional involvement in the IT industry. Worked in successful projects involving mainly the Service Oriented Application by contributing to all requirements gathering, design and implementation phases. He is having experience with SOA applications development, Microsoft .NET, BizTalk, He is member of Charted It professional in UK.

Solution Architect

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170813.1 | Last Updated 1 Jul 2011
Article Copyright 2011 by Pubudu Kasakara
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid