ASP.NET Tutorial
Estimated reading: 4 minutes 271 views

ASP.NET Web Services & AJAX โ€“ Build Fast, Interactive Web Apps

Introduction โ€“ Power Up Your ASP.NET Apps with Services & AJAX

Modern web applications demand asynchronous communication to provide a smooth, dynamic user experience. ASP.NET offers powerful support for building Web Services and AJAX-enabled components, enabling data updates without full page reloads and seamless backend interactions.

In this guide, youโ€™ll learn:

  • How to create and consume ASP.NET Web Services (ASMX)
  • How AJAX enhances performance and responsiveness
  • How to use UpdatePanel and ScriptManager in Web Forms
  • How to integrate classic ASP-style AJAX patterns

Topics Covered

Topic Description
ASP.NET โ€“ Web ServicesBuild and consume ASMX/SOAP services for backend logic
ASP.NET โ€“ AJAX ControlUse ScriptManager, UpdatePanel, and asynchronous postbacks
Classic ASP โ€“ AJAX (Merged)Legacy AJAX techniques using XMLHttpRequest and IFRAME tricks

ASP.NET โ€“ Web Services

ASP.NET supports SOAP-based Web Services using .asmx files.

Creating an ASMX Service

// HelloWorld.asmx
[WebService(Namespace = "http://example.com/")]
public class HelloWorld : WebService {
    [WebMethod]
    public string Greet(string name) {
        return "Hello " + name;
    }
}

Access via URL like:
http://yourdomain.com/HelloWorld.asmx?wsdl


Consuming Web Services

From another .NET project:

  1. Add Service Reference โ†’ Enter WSDL URL
  2. Use the auto-generated proxy class:
HelloWorldSoapClient client = new HelloWorldSoapClient();
string msg = client.Greet("Alice");

Can also use tools like WCF, HttpClient, or even jQuery/AJAX to call ASMX.


ASP.NET โ€“ AJAX Controls (Web Forms)

AJAX allows partial updates on the page without full reloads.

ScriptManager & UpdatePanel

<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
  <ContentTemplate>
    <asp:Label ID="lblTime" runat="server" />
    <asp:Button ID="btnUpdate" Text="Refresh Time" runat="server" OnClick="btnUpdate_Click" />
  </ContentTemplate>
</asp:UpdatePanel>

Code-behind:

protected void btnUpdate_Click(object sender, EventArgs e) {
    lblTime.Text = DateTime.Now.ToString();
}

Only the UpdatePanel refreshesโ€”reducing bandwidth and flicker.


Timer Control for Auto-Refresh

<asp:Timer ID="Timer1" runat="server" Interval="10000" OnTick="Timer1_Tick" />

Refresh parts of the page every 10 seconds.


AJAX Control Toolkit

Includes:

  • AutoCompleteExtender
  • ModalPopup
  • Accordion
  • CalendarExtender

Install via NuGet: Install-Package AjaxControlToolkit


Classic ASP โ€“ AJAX (Legacy Concepts)

In older Classic ASP environments, AJAX was handled using JavaScript and XMLHttpRequest manually:

var xhr = new XMLHttpRequest();
xhr.open("GET", "getTime.asp", true);
xhr.onreadystatechange = function() {
  if (xhr.readyState === 4 && xhr.status === 200) {
    document.getElementById("timeBox").innerHTML = xhr.responseText;
  }
};
xhr.send();

Still useful for understanding raw AJAX principles in modern SPA frameworks.


Summary โ€“ Recap & Next Steps

ASP.NETโ€™s integration of Web Services and AJAX controls allows for scalable, responsive applications. Whether you use ASMX for legacy SOAP or AJAX controls for partial postbacks, these tools form the foundation of dynamic web interactivity.

Key Takeaways:

  • ASMX services offer SOAP-based interop across platforms
  • ScriptManager and UpdatePanel simplify AJAX in Web Forms
  • AJAX Control Toolkit provides rich UI components
  • Use partial page updates to improve speed and UX
  • Classic AJAX (JS + XHR) still underpins modern client-side frameworks

Real-World Applications:

  • Chat applications with auto-refresh panels
  • Currency or weather widgets with UpdatePanel
  • SOAP-based B2B APIs
  • AJAX-based auto-search and validation forms

Frequently Asked Questions

Can I use Web Services with modern JavaScript apps?
Yes. Use $.ajax in jQuery or fetch() to call ASMX services (they return XML by default).


Whatโ€™s the difference between REST API and ASMX Web Service?
ASMX uses SOAP (XML-heavy); REST APIs (in ASP.NET Core) use lightweight JSON over HTTP.


Is UpdatePanel supported in ASP.NET Core?
No. UpdatePanel is Web Forms-specific. In Core, use Blazor or fetch APIs with JavaScript.


How can I debug AJAX calls in ASP.NET?
Use browser dev tools โ†’ Network tab โ†’ check AJAX requests and responses.


Share Now :
Share

๐ŸŒ ASP.NET Web Services & AJAX

Or Copy Link

CONTENTS
Scroll to Top