Click here to Skip to main content
14,302,993 members

Sample code for AJAX in VB.NET, ASP.NET without using Ajax.dll

Rate this:
2.35 (8 votes)
Please Sign up or sign in to vote.
2.35 (8 votes)
6 Feb 2007CPOL
Sample project containing source code to implement AJAX without Ajax.dll in VB.NET, ASP.NET.

Sample image


AJAX stands for Asynchronous JavaScript and XML. Beginners may find it hard when they want to learn AJAX. They may get confused when they see samples using Atlas. This article is mainly for beginners of AJAX. The sample code is very easy and self-understandable. This code does not use Ajax.dll. It uses the XmlHttp object to do the AJAX implementation.

Using the code

Download the source code, unzip it, and configure it in your IIS. The folder "Ajax_VB.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 an Insert query in the SQL file.

Execute the project Ajax_VB.Net. Click the button. The button is an HTML button. It takes employee data from the table 'employee' without page post-back and populates the data in the dropdownlist. When a particular record is selected in the dropdownlist, the selected employee name and employee ID will be displayed in the label.

What is AJAX?

AJAX stands for Asynchronous JavaScript and XML. It is a browser technology. It is a combination of JavaScript and XML. Data is transferred in the form of XML. The XMLHttp object is used in AJAX for data transfer.


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

The GetData() function calls the GetEmployeeDetails page. In that page, employee details are retrieved from the database and returned back to the calling JavaScript function. From the Response object, the return value is evaluated and bound to the dropdownlist.

Sample source code

var xmlHttp

function GetData()

    if (xmlHttp==null)
        alert ("Browser does not support HTTP Request")

    var url="GetEmployeeDetails.aspx"

function stateChanged() 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
        var response=xmlHttp.responseText;

            alert("No Record Found !!!");
        else if(response=='Error')
            alert("An Error occured in accessing the DataBase !!!");
            var arr=response.split("~");
            var empID=arr[0].split(",");
            var empName=arr[1].split(",");


            for(var i=0;i<empID.length;i++)
                var o = document.createElement("option");
                o.value = empID[i];
                o.text = empName[i];

function GetXmlHttpObject()
    var objXMLHttp=null

    if (window.XMLHttpRequest)
        objXMLHttp=new XMLHttpRequest()
    else if (window.ActiveXObject)
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    return objXMLHttp

function display()
    var selIndex=document.getElementById("dlistEmployee").selectedIndex;
    var empName=document.getElementById("dlistEmployee").options(selIndex).text;
    var empID=document.getElementById("dlistEmployee").options(selIndex).value;

    document.getElementById("lblResult").innerHTML="You have selected " + 
                            empName + " ( ID : " + empID + " )";


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


About the Author

Bala Murali S
Web Developer
India India
No Biography provided

Comments and Discussions

GeneralAjax dll is not working on godaddy server Pin
Akeel Qureshi28-Sep-09 3:20
memberAkeel Qureshi28-Sep-09 3:20 

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

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

Posted 6 Feb 2007


28 bookmarked