In this article we will introduce with ScriptManager control in ASP.NET using C#.
ScriptManager Example in ASP.NET using C#
ScriptManager is used in ASP.NET for using AJAX controls. It serves as the bridge between the client page and the Ajax Framework. In this example we use UpdatePanel and a button when you will click on update time button it will show the current time. The syntax of ScriptManager are following:
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>
ScriptManager.aspx (Design Page):
ScriptManager.aspx (source code):
<%@ Page Title="" Language="C#" MasterPageFile="~/RoseindiaMaster.master" AutoEventWireup="true" CodeFile="ScriptManager.aspx.cs" Inherits="ScriptManager" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <div> <h2 style="color: Green"> ScriptManager in ASP.NET 4, C#</h2> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Button runat="server" ID="Button1" Text="Update Time" OnClick="Button1_Click" Width="118px" /> <br /> <br /> <asp:Label runat="server" ID="Label1" Font-Bold="True" Font-Names="Cambria" Font-Size="X-Large" ForeColor="#CC0000" /> </ContentTemplate> </asp:UpdatePanel> </div> </asp:Content>
ScriptManager.aspx.cs (C# code file):
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class ScriptManager : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Label1.Text = "Current Time : " + System.DateTime.Now.ToLongTimeString(); } }
Output:
When you will run the application it will show just like that.
Now when you click the update time button it will show the current time.
Download source code
[ 0 ] Comments