Click here to Skip to main content
Click here to Skip to main content

Sample Code for Ajax in C#.net,Asp.net with Ajax.dll

, 6 Feb 2007
Rate this:
Please Sign up or sign in to vote.
This project is used to easily understand and implement Ajax in C#.net , ASP.Net with Ajax.dll
Sample image

Introduction

Ajax stands for Asynchronous Javascript and XML. Beginners may feel hard when they want to learn Ajax. They may got confused when they get into the samples like Atlas. This article is mainly for beginners of Ajax. The sample code is very easy and self-understandable.

Using The Code

Download the source code , unzip it and configure it in your IIS. The folder "Ajax_CSharp.Net" contains a sub-folder named "DB Table". This sub-folder contains a sql file. Execute the sql in your local sql server. A table with the name "employee" will be created. Add some more data into the table with the insert query in the sql file.

Execute the project Ajax_CSharp.net. Click the button. The button is a html button.It takes employee data from the table 'employee' without page post-back and populate the data in the dropdownlist. When a particular record is selected in the dropdownlist, the selected employee name and employee id willl be displayed in the label.

What is Ajax?

Ajax stands for Asynchronous Javascript and XML. It is a browser technology. This is an combination of Javascript and XML. The data is transfered in the form of XML. XMLHttp object is used in Ajax.

Why Ajax?

Ajax is used to eliminate round-trip to the server, when a request is posted to the server. In simple, we can say that when we want to access the database without page refresh, we can use Ajax.

Source Code

Page_Load()
protected void Page_Load(object sender, EventArgs e)
    {
        Ajax.Utility.RegisterTypeForAjax(typeof(Ajax_CSharp));
    }

Get_Data()
[Ajax.AjaxMethod(HttpSessionStateRequirement.ReadWrite)]
    public string GetData()
    {
    //contains function to hit database
    }

Using Javascript

Javascript plays an vital role in Ajax. The server side function GetData() is a Ajax function. The function is coded with "[Ajax.AjaxMethod(HttpSessionStateRequirement.ReadWrite)]" which shows that it is an Ajax function. This function is called from javascript in the click event of the button.

The server side function returns some value which is again handled by the javascript. HttpSessionStateRequirement.Readwrite is an optional argument which is used in order to use session variables inside ajax function. One thing we have to remember is that we can't access server side controls inside the GetData() function. Thats why we are returning the data to the javascript and populate dropdownlist from the javascript.

function GetData()
    {
        var response;
        Ajax_CSharp.GetData(GetData_CallBack);    
    }
    
    function GetData_CallBack(response)
    {
        var response=response.value;
     // code to handle response value
        
     }

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Bala Murali S
Web Developer
India India
No Biography provided

Comments and Discussions

 
GeneralMy vote of 5 Pinmemberjeevav10-Aug-10 19:11 
GeneralSuperrrrr man, kazhakal kazhai...india va kokka....mmmuack Pinmembervsstephen27-Jul-10 18:35 
GeneralGood start PinmemberWaruna3-Oct-09 17:56 
GeneralNeeds more Pinmemberfly90417-Mar-09 6:23 
QuestionNot working for Firefox PinmemberMember 83707622-Jan-09 7:19 
GeneralCould not find the project file PinmemberHemJoshi10-Sep-08 22:22 
GeneralRegarding Ajax drop down with Text box PinmemberMani Kumar21-Feb-08 21:37 
GeneralHelps beginners Pinmemberwebqa30-Apr-07 19:14 
GeneralIt's Useful PinmemberFlorence Juliet J9-Feb-07 18:44 
GeneralWhere is the javascript PinmvpMark Nischalke7-Feb-07 2:26 
GeneralRe: Where is the javascript PinmemberBala Murali S8-Feb-07 19:59 
GeneralRe: Where is the javascript PinmvpMark Nischalke9-Feb-07 2:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 7 Feb 2007
Article Copyright 2007 by Bala Murali S
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid