Download presentation
Presentation is loading. Please wait.
1
ASP.Net AJAX
2
AJAX Asynchronous JavaScript and XML: – JavaScript, Document Object Model, Cascade Style Sheet, XML, server-side script such as.Net, etc. Partial refresh: It lets you update part of a web page without having to reload the entire page. RIA: Rich Internet Application – Quick response time, interactive page
4
How AJAX Updates a Page When an event happens, JavaScript (AJAX engine) prepares a request and sends it to the web sever. The server receives the request and processes it. The server prepares a response and sends it back to the browser. The JavaScript parses the response to update the page.
5
ASP.Net AJAX Server Controls ScriptManager: Enables the use of other AJAX controls. UpdatePanel: A control that encloses standard ASP.net controls to be updated asynchronously (asynchronous postback) Timer control: Trigger partial refresh at a set time interval.
6
Creating Page with AJAX 1. Add a ScriptManager control 2. Add UpdatePanel control 3. Add ASP.Net controls to the UpdatePanel
7
Postback or Asynchronous PostBack Page.IsPostBack ScriptManager1.IsInAsyncPostBack
8
Example 1: Two Counters
9
Dim PostbackCounter, AsyncCounter As Integer Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then Session("PCounter") = PostbackCounter Session("Acounter") = AsyncCounter Else PostbackCounter = Session("PCounter") End If If ScriptManager1.IsInAsyncPostBack Then AsyncCounter = Session("Acounter") End If End Sub Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click PostbackCounter += 1 TextBox1.Text = PostbackCounter.ToString Session("PCounter") = PostbackCounter End Sub Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click AsyncCounter += 1 TextBox2.Text = AsyncCounter.ToString Session("Acounter") = AsyncCounter End Sub
10
Example 2: Retrieve Customer Name
11
Page.IsPostBack and ScriptManager1.IsInAsyncPostBack Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then TextBox3.Text = "First time" Else TextBox3.Text = "PostBack" End If If ScriptManager1.IsInAsyncPostBack Then TextBox2.Text = " IsAsyncPostBack" Else TextBox2.Text = " Not AsyncPostBack" End If End Sub
12
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\salesDB.mdb" Dim objConn As New OleDbConnection(strConn) Dim strSQL As String = "select * from customer where cid='" & TextBox1.Text & "';" Dim objComm As New OleDbCommand(strSQL, objConn) objConn.Open() Dim objDataReader As OleDbDataReader objDataReader = objComm.ExecuteReader() objDataReader.Read() TextBox2.Text = objDataReader("cname") objDataReader.Close() End Sub
13
AJAX Timer Add inside the UpdatePanel Add Timer as a Trigger to the UpdatePanel – UpdateTriggers property Timer’s interval and tick event
14
Code Example Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick Label1.Text = DateTime.Now.ToLongTimeString() End Sub
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.