ASP.NET Tutorial
Estimated reading: 4 minutes 39 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 :

Leave a Reply

Your email address will not be published. Required fields are marked *

Share

๐ŸŒ ASP.NET Web Services & AJAX

Or Copy Link

CONTENTS
Scroll to Top