Congratulations to all monthly winners of May 2013 !!! They have won INR 2900 cash and INR 27497 worth prize.
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 12600 |  Welcome, Guest!   Register  Login
Home > Articles > ASP.NET AJAX > Showing Clock Without Page Load Every Time using ASP.NET AJAX

Showing Clock Without Page Load Every Time using ASP.NET AJAX

1 vote(s)
Rating: 3 out of 5
Article posted by Gopesh9 on 8/3/2012 | Views: 4582 | Category: ASP.NET AJAX | Level: Beginner | Points: 250 red flag

Advertisements

Advertisements
I have just started reading Ajax and came across very nice topic to show the clock in the label and every one second it is changing without loading the page again and again. You can also use it as forming a software for stop watch and all.

Introduction

ASP.NET AJAX enables a Web application to retrieve data from the server asynchronously and to refresh parts of the existing page. This improves the user experience by making the Web application more responsive. In this article, I will show you how to build an AJAX-enabled ASP.NET MVC application.

Objective

Topic to show the clock in the label and every one second it is changing without loading the page again and again. You can also use it as forming a software for stop watch and all.

Using the code

In your default.aspx write......

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server"></head>

<body><form id="form1" runat="server"><div>

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

<br /><br /></div>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">

<Triggers><asp:AsyncPostBackTrigger ControlID="Timer2" EventName="tick" /></Triggers>

<ContentTemplate>

<asp:Timer ID="Timer2" runat="server" Interval="1"></asp:Timer>

<br /><asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

</ContentTemplate></asp:UpdatePanel>

<br /><br />

<asp:UpdatePanel ID="UpdatePanel2" runat="server">

<Triggers><asp:AsyncPostBackTrigger ControlID="Timer2" EventName="tick" /></Triggers>

<ContentTemplate><asp:Label ID="Label2" runat="server" Text="Label"></asp:Label></ContentTemplate>

</asp:UpdatePanel><br /><br />

</form></body></html>

In this I have used a script manager which can only be one in a webpage and many update panel. All the controls which I want to load without loading the page must be written within the update panel.

In the Default.aspx.cs file i will write the code for the time..

public partial class _Default : System.Web.UI.Page

{

   protected void Page_Load(object sender, EventArgs e)

    {

     Label1.Text = DateTime.Now.ToLongTimeString();

     Label2.Text = DateTime.Now.TimeOfDay.ToString();

    }

}

The time will be automatically chnages every one second.

Conclusion

You can do many thing using Ajax. Here I have just showed how you can use Ajax in your programming. Any Suggestions to improve the code is Welcomed as I am only a beginner in the .Net development.

Happy Programming. Thank You

Advertisements

If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Page copy protected against web site content infringement by Copyscape
Found interesting? Add this to:



Please Sign In to vote for this post.

About G. S.

Experience:0 year(s)
Home page:http://www.dotnetfunda.com
Member since:Friday, August 03, 2012
Level:Starter
Status: [Member]
Biography:A Dot Net Learner. Currently working in Software Company.
>> Write Response - Respond to this post and get points
Related Posts

Using Validation Controls is faster than doing validation on the server side. Please note that there are some cases where you can’t set a rule. In that Case you will add those types of validation to your Business Logic Layer, when you validate in your Class Library before sending the Data to the Data Layer to be executed. There is only one reason why Microsoft created Validation controls. The Reason is simple “Never Trust the user input”

An Ajax DLL is used to call server side method asynchronously without processing the whole page life cycle.

In this example i am implementing the AutoComplete functionality to textbox in the EditItemTemaplate of GridView using AJAX autocomplete extender, for this we need to create a web service which calls the method to fetch data from database and display results as suggestions for textbox

This article describes how to use ASP.NET AJAX PageMethods to submit data to the server and get response. It also shows how to serialize object into JSON format and access its properties in JavaScript.

In this article we will see how to check whether username exists in database or not without refreshing the page using ajax updatepanel control.

More ...
About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 6/19/2013 4:29:02 PM