๐ŸŒ ASP.NET Web Services & AJAX
Estimated reading: 4 minutes 42 views

๐Ÿ”„ ASP.NET โ€“ AJAX Control โ€“ Enhance User Experience with Partial Page Updates

๐Ÿงฒ Introduction โ€“ What Is AJAX Control in ASP.NET?

AJAX (Asynchronous JavaScript and XML) in ASP.NET allows you to update parts of a web page without reloading the entire page. ASP.NET provides built-in AJAX controls through the ScriptManager, UpdatePanel, Timer, and UpdateProgress, which enable rich user interactions and improved performance with minimal effort.

๐ŸŽฏ In this guide, youโ€™ll learn:

  • What ASP.NET AJAX controls do and why they matter
  • How to use ScriptManager, UpdatePanel, and Timer
  • Real-world AJAX-enabled form examples
  • Output, behavior, and performance best practices

๐Ÿ’ก What Are ASP.NET AJAX Controls?

AJAX controls enable partial page rendering, allowing sections of a page to be updated without a full postback. This results in:

  • Faster response time
  • Better user experience
  • Reduced server load

ASP.NET AJAX is integrated using the System.Web.UI namespace and the AjaxControlToolkit.


๐Ÿงฐ Core ASP.NET AJAX Controls

๐Ÿงฉ Control๐Ÿ“Œ Purpose
ScriptManagerEnables AJAX functionality in the page
UpdatePanelUpdates part of the page asynchronously
UpdateProgressDisplays progress during asynchronous postbacks
TimerTriggers asynchronous updates at timed intervals

๐Ÿงช Basic Example โ€“ Partial Update with UpdatePanel

<asp:ScriptManager ID="ScriptManager1" runat="server" />

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:Label ID="lblTime" runat="server" />
        <asp:Button ID="btnUpdate" runat="server" Text="Refresh Time" OnClick="btnUpdate_Click" />
    </ContentTemplate>
</asp:UpdatePanel>
protected void btnUpdate_Click(object sender, EventArgs e)
{
    lblTime.Text = "Server Time: " + DateTime.Now.ToString();
}

๐Ÿ” Explanation:

  • ScriptManager enables AJAX
  • UpdatePanel allows only the label/button region to update
  • Postback is done asynchronously

๐Ÿงช Output:
Only the label is updated when the button is clickedโ€”no full page refresh.


โฑ๏ธ Example โ€“ Auto Refresh with Timer Control

<asp:ScriptManager ID="ScriptManager1" runat="server" />

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:Label ID="lblClock" runat="server" />
        <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick" />
    </ContentTemplate>
</asp:UpdatePanel>
protected void Timer1_Tick(object sender, EventArgs e)
{
    lblClock.Text = DateTime.Now.ToLongTimeString();
}

๐Ÿ” Output:
Label updates every second with the current time.


๐ŸŒ€ Showing Loading Animation โ€“ UpdateProgress

<asp:ScriptManager ID="ScriptManager1" runat="server" />

<asp:UpdateProgress ID="UpdateProgress1" runat="server">
    <ProgressTemplate>
        <img src="loading.gif" alt="Loading..." />
    </ProgressTemplate>
</asp:UpdateProgress>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:Label ID="lblData" runat="server" />
        <asp:Button ID="btnLoad" runat="server" Text="Load Data" OnClick="btnLoad_Click" />
    </ContentTemplate>
</asp:UpdatePanel>
protected void btnLoad_Click(object sender, EventArgs e)
{
    System.Threading.Thread.Sleep(3000); // Simulate delay
    lblData.Text = "Data loaded at " + DateTime.Now;
}

๐Ÿงช Output:
Displays loading.gif while the server-side code executes.


๐Ÿ“˜ Best Practices for ASP.NET AJAX Controls

โœ… Do:

  • Use AJAX for minor updates (not large-scale content replacement)
  • Always wrap AJAX controls within ScriptManager
  • Use UpdatePanel sparingly to avoid performance degradation

โŒ Avoid:

  • Nesting UpdatePanels unnecessarily
  • Using AJAX to call long-running server operations
  • Forgetting to handle postback scenarios gracefully

๐Ÿ“Œ Summary โ€“ Recap & Next Steps

ASP.NET AJAX controls allow dynamic, partial updates in web pages without full postbacks. This improves performance, user interactivity, and scalability when used appropriately with UpdatePanel, ScriptManager, Timer, and UpdateProgress.

๐Ÿ” Key Takeaways:

  • Use ScriptManager to activate AJAX functionality
  • Wrap partial UI sections in UpdatePanel
  • Combine Timer and UpdateProgress for interactive dashboards

โš™๏ธ Real-world Use Cases:

  • Live chat boxes
  • Real-time notifications
  • Partial form updates (e.g., dependent dropdowns)

โ“ FAQs โ€“ ASP.NET AJAX Control


โ“ What is the purpose of ScriptManager?
โœ… It manages AJAX scripts and enables asynchronous postbacks in the page.


โ“ Can I use multiple UpdatePanels on the same page?
โœ… Yes, but excessive use may impact performance. Prefer targeting only necessary areas.


โ“ Is UpdatePanel supported in ASP.NET Core?
โœ… No. UpdatePanel is specific to Web Forms. Use JavaScript or AJAX libraries in ASP.NET Core instead.


โ“ How does Timer control work with UpdatePanel?
โœ… It triggers a postback at a defined interval, updating content inside the UpdatePanel.


Share Now :

Leave a Reply

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

Share

๐Ÿ”„ ASP.NET โ€“ AJAX Control

Or Copy Link

CONTENTS
Scroll to Top