SlideShare une entreprise Scribd logo
1  sur  52
ASP.Net AJAX

          JULIE ISKANDER
MSc. COMMUNICATION AND ELECTRONICS
Lecture 1 Outlines

 JavaScript in ASP.NET
   Adding Client-side events through ASP.NET

 Fundamentals AJAX
 AJAX ASP.Net
 AJAX ASP.Net Controls
JavaScript in ASP.NET
JavaScript Essentials

 Ways to embed JavaScript code in a web page:
  1. Directly in an event attribute for an HTML element.
  2. Add a <script> tag that contains the JavaScript code.
     1.   The code an be run automatically when the page loads
     2.   Inserted in a JavaScript function that will be called in response
          to a client-side event.
 External Javascript file (.js) can be linked to a
  webpage using <script> tag with src attribute taking
  the js file url
 HTML Document Object Model (DOM)
 Client Side Events
OnClientClick Property

 Button, ImageButton , LinkButton
 To add client-side code to the button click
 If the JS code returns true postback is called
 Else  postback is canceled
Adding Clientside events through asp.net
Rendering Script Blocks

 Page.ClientScript Methods
    RegisterClientScriptInclude(): This method adds a
     script tag that references an external js file at the top of
     the rendered page.
    RegisterClientScriptBlock(): Writes a script block at
     the beginning of the web form, right after the <form
     runat="server"> tag
    RegisterStartupScript(): Writes a script block at the end
     of the web form, right before the closing </form> tag
AJAX
Asynchronous
Javascript And XML
AJAX

 Asynchronous Javascript And Xml
 Does things behind the scenes
 Looks a lot more like desktop application then web
  applications
 No need to refresh the whole page at each interaction
  with the server
 Modifies page on the fly
 JavaScript binds everything together
Traditional Web Application Vs. AJAX Web
                  Application

 Traditional Web application
Traditional Web Application VS. AJAX Web
                 Application

 AJAX Web application
Steps to do a simple ajax request to get data

1.   Create XMLHttpRequest Object
2.   Open the request, set the HTTP method and URL
3.   Set callback for onreadychange
4.   Send asynchronous request
5.   Create an event to call the previous steps



                 All this is JAVASCRIPT Code
1- Creating the XMLHttpRequest Object
STEPS 2,3 and 4
readyState values



Value      Description
0          Uninitialized
1          Loading
2          Loaded
3          Interactive
4          Complete
Some status values



Value      Description
200        Ok
204        No content
401        UnAuthorized
404        Not Found
411        Request Timeout
Calling Ajax request
Custom HTTP handler .ashx

 A light-weight option as it doesn’t use the full-page
  model.
 A class that implements IHttpHandler
    void ProcessRequest(HttpContext context)
    bool IsReusable
Example using ASHX
Custom HTTP handler.ashx
.aspx that calls .ashx using ajax
The .js file
Ajax and Client Callbacks

1. A JavaScript event fires, triggering the server
   callback.
2. The normal page life cycle occurs.
3. ASP.NET executes the server-side callback method.
   It accepts a single string parameter and returns a
   single string.
4. The page receives the response from the server-side
   method, it uses JavaScript code to modify the web
   page accordingly.
Ajax and Client Callbacks

 The Page must implement ICallbackEventHandler
 Must Implement
   public void RaiseCallbackEvent(string eventArgument)

   public string GetCallbackResult()
Ajax and Client Callbacks
ASP.NET
AJAX
ASP.NET AJAX

 Successor of Atlas
 Was first a separate component in ASP.NET 2.0 then
  become completely integrated.
 ASP.NET AJAX is made up of:
    ASP.NET AJAX on the Client
    ASP.NET AJAX on the Server
ASP.NET AJAX on the Client

 JavaScript files, in System.Web.Extensions.dll
   MicrosoftAjax.js, MicrosoftAjaxWebForms.js, and
    MicrosoftAjaxTimer.js.)
ASP.NET AJAX on the Server

 ScriptManager,
   is the brains of the server-side ASP.NET AJAX model.

   No visual appearance on the page.

   renders the links to the ASP.NET AJAX JavaScript libraries.

 Each page that uses ASP.NET AJAX requires an
  instance of the ScriptManager.
 A page can has one and only one ScriptManager.
ASP.NET
AJAX Server
Control
The ASP.NET AJAX Server Controls

                 Manages script libraries and script
ScriptManager    files, partial-page rendering, and other
                 functions.
                 Enables sections of a page to be
UpdatePanel      partially rendered without a page
                 postback.
                 Provides visual feedback on the
UpdateProgress   browser when the contents on
                 UpdatePanel controls refresh.
                 Performs partial-page updates at
Timer
                 defined intervals.
ASP.NET AJAX Server Control

 Create partial-page update
 Emit the ASP.NET AJAX script needed
 Disadvantage
   Reduced flexibility
Example
ASP.NET AJAX Server Control

 ScriptManager
   Must be added before any other AJAX control.

   Control manages the client-side scripts that enable
    asynchronous Ajax functionality.
   Only   ONE ScriptManager per page.
ASP.NET AJAX Server Control

 UpdatePanel
   Isolating a section of a page for a partial-page update.

   Intercept any submit event on it and call asynchronous
    callback to refresh it content.
   Any content that’s outside the panel and changed is ignored.

   UpdateMode Property is Always or Conditional
     Always  updates with any partial update
     Conditional  updated independently
ASP.NET AJAX Server Control

 UpdatePanel Triggers
   Triggers to render UpdatePanel on event occurrence .

   Triggers link controls outside the panel

   To specify when an UpdatePanel should update, you need to
    define an UpdatePanel trigger.
     AsyncPostBackTrigger
                          updates only UpdatePanels with
      UpdateMode Always and Conditional with the trigger
     PostBackTrigger
ASP.NET AJAX Server Control

 Timer Control
   Interval Property to set maximum number of milliseconds
    before next update.
   If on an UpdatePanel triggers asynchronous postback

   If not on one, nor linked in a trigger  causes full page
    postback
ASP.NET AJAX Server Control

 UpdateProgress Control
   Specify some content that will appear as soon as an
    asynchronous request is started and disappear as soon as the
    request is finished.
   Can include a fixed message or image.
Note

 When the callback is performed, the target page
 actually starts executing a trimmed-down life cycle.
    Control events won’t execute, but the Page.Load and Page.Init
     event
 Page.IsPostBack = true,
 Page.IsCallback =true
 No page rendering.
 View state information is retrieved
 Any changes made are not sent back to the page.
 Only strings can be sent and received.
Ajax Control Toolkit

 http://www.asp.net/ajaxlibrary/act.ashx
   Open Source toolkit for AJAX controls and extenders.

 http://stephenwalther.com/blog/archive/2011/11/16
  /ajax-control-toolkit-november-2011-release.aspx
     Read about changes to 2011 release
Lab #1

 Try the lecture examples again.
   Use javascript to read xml and txt files

 Download Ajax control toolkit
 Try lecture Examples
References

 [1] Pro ASP.NET In C# 2010, Fourth
  Edition,matthew Macdonald, Adam Freeman, And
  Mario Szpuszta, Apress
 [2]Profesional ASP.NET 4 in C# and VB.NET, Bill
  Evjen, Scott Hanselman and Devin Rader, Wiley
 [3] http://www.adaptivepath.com/ideas/ajax-new-
  approach-web-applications

Contenu connexe

Tendances (20)

Ajax
AjaxAjax
Ajax
 
ASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server ControlsASP.NET 03 - Working With Web Server Controls
ASP.NET 03 - Working With Web Server Controls
 
Jquery Ajax
Jquery AjaxJquery Ajax
Jquery Ajax
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
 
AJAX
AJAXAJAX
AJAX
 
Ajax Ppt 1
Ajax Ppt 1Ajax Ppt 1
Ajax Ppt 1
 
Ajax
AjaxAjax
Ajax
 
PHP - Introduction to PHP AJAX
PHP -  Introduction to PHP AJAXPHP -  Introduction to PHP AJAX
PHP - Introduction to PHP AJAX
 
Ajax PPT
Ajax PPTAjax PPT
Ajax PPT
 
Ajax Presentation
Ajax PresentationAjax Presentation
Ajax Presentation
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
Ajax ppt - 32 slides
Ajax ppt - 32 slidesAjax ppt - 32 slides
Ajax ppt - 32 slides
 
Ajax and PHP
Ajax and PHPAjax and PHP
Ajax and PHP
 
Introduction to ajax
Introduction to ajaxIntroduction to ajax
Introduction to ajax
 
Using Ajax In Domino Web Applications
Using Ajax In Domino Web ApplicationsUsing Ajax In Domino Web Applications
Using Ajax In Domino Web Applications
 
Web controls
Web controlsWeb controls
Web controls
 
Ajax part i
Ajax part iAjax part i
Ajax part i
 
Advantages and disadvantages of an ajax based client application
Advantages and disadvantages of an ajax based client applicationAdvantages and disadvantages of an ajax based client application
Advantages and disadvantages of an ajax based client application
 

En vedette

En vedette (20)

Electronic data interchange
Electronic data interchangeElectronic data interchange
Electronic data interchange
 
Controls in asp.net
Controls in asp.netControls in asp.net
Controls in asp.net
 
Presentation - Electronic Data Interchange
Presentation - Electronic Data InterchangePresentation - Electronic Data Interchange
Presentation - Electronic Data Interchange
 
State Management in ASP.NET
State Management in ASP.NETState Management in ASP.NET
State Management in ASP.NET
 
Asp.net.
Asp.net.Asp.net.
Asp.net.
 
Asp.Net Control Architecture
Asp.Net Control ArchitectureAsp.Net Control Architecture
Asp.Net Control Architecture
 
Intro To Asp Net And Web Forms
Intro To Asp Net And Web FormsIntro To Asp Net And Web Forms
Intro To Asp Net And Web Forms
 
Validation controls in asp
Validation controls in aspValidation controls in asp
Validation controls in asp
 
Electronic data interchange
Electronic data interchangeElectronic data interchange
Electronic data interchange
 
Ch3 server controls
Ch3 server controlsCh3 server controls
Ch3 server controls
 
State management in ASP.NET
State management in ASP.NETState management in ASP.NET
State management in ASP.NET
 
State management
State managementState management
State management
 
Standard control in asp.net
Standard control in asp.netStandard control in asp.net
Standard control in asp.net
 
Introduction to ASP.NET
Introduction to ASP.NETIntroduction to ASP.NET
Introduction to ASP.NET
 
Presentation on asp.net controls
Presentation on asp.net controlsPresentation on asp.net controls
Presentation on asp.net controls
 
Validation controls ppt
Validation controls pptValidation controls ppt
Validation controls ppt
 
Seminar ppt on digital signature
Seminar ppt on digital signatureSeminar ppt on digital signature
Seminar ppt on digital signature
 
ASP.NET State management
ASP.NET State managementASP.NET State management
ASP.NET State management
 
How to make more impact as an engineer
How to make more impact as an engineerHow to make more impact as an engineer
How to make more impact as an engineer
 
Edi ppt
Edi pptEdi ppt
Edi ppt
 

Similaire à Ajax and ASP.NET AJAX (20)

Web forms in ASP.net
Web forms in ASP.netWeb forms in ASP.net
Web forms in ASP.net
 
Asp.Net Ajax Component Development
Asp.Net Ajax Component DevelopmentAsp.Net Ajax Component Development
Asp.Net Ajax Component Development
 
Walther Ajax4
Walther Ajax4Walther Ajax4
Walther Ajax4
 
C sharp and asp.net interview questions
C sharp and asp.net interview questionsC sharp and asp.net interview questions
C sharp and asp.net interview questions
 
Integrating ASP.NET AJAX with SharePoint
Integrating ASP.NET AJAX with SharePointIntegrating ASP.NET AJAX with SharePoint
Integrating ASP.NET AJAX with SharePoint
 
ASP.NET - Web Programming
ASP.NET - Web ProgrammingASP.NET - Web Programming
ASP.NET - Web Programming
 
13 asp.net session19
13 asp.net session1913 asp.net session19
13 asp.net session19
 
Asp
AspAsp
Asp
 
Programming web application
Programming web applicationProgramming web application
Programming web application
 
Ajax
AjaxAjax
Ajax
 
SynapseIndia asp.net2.0 ajax Development
SynapseIndia asp.net2.0 ajax DevelopmentSynapseIndia asp.net2.0 ajax Development
SynapseIndia asp.net2.0 ajax Development
 
SynapseIndia dotnet development ajax client library
SynapseIndia dotnet development ajax client librarySynapseIndia dotnet development ajax client library
SynapseIndia dotnet development ajax client library
 
ASP.NET Lecture 1
ASP.NET Lecture 1ASP.NET Lecture 1
ASP.NET Lecture 1
 
ASP.Net Presentation Part1
ASP.Net Presentation Part1ASP.Net Presentation Part1
ASP.Net Presentation Part1
 
React JS .NET
React JS .NETReact JS .NET
React JS .NET
 
Ajax
AjaxAjax
Ajax
 
Chanhao Jiang And David Wei Presentation Quickling Pagecache
Chanhao Jiang And David Wei Presentation Quickling PagecacheChanhao Jiang And David Wei Presentation Quickling Pagecache
Chanhao Jiang And David Wei Presentation Quickling Pagecache
 
.Net course-in-mumbai-ppt
.Net course-in-mumbai-ppt.Net course-in-mumbai-ppt
.Net course-in-mumbai-ppt
 
A View about ASP .NET and their objectives
A View about ASP .NET and their objectivesA View about ASP .NET and their objectives
A View about ASP .NET and their objectives
 
Asp.Net Page Life
Asp.Net Page LifeAsp.Net Page Life
Asp.Net Page Life
 

Plus de Julie Iskander (20)

HTML 5
HTML 5HTML 5
HTML 5
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
C for Engineers
C for EngineersC for Engineers
C for Engineers
 
Design Pattern lecture 3
Design Pattern lecture 3Design Pattern lecture 3
Design Pattern lecture 3
 
Scriptaculous
ScriptaculousScriptaculous
Scriptaculous
 
Prototype Framework
Prototype FrameworkPrototype Framework
Prototype Framework
 
Design Pattern lecture 4
Design Pattern lecture 4Design Pattern lecture 4
Design Pattern lecture 4
 
Design Pattern lecture 2
Design Pattern lecture 2Design Pattern lecture 2
Design Pattern lecture 2
 
Design Pattern lecture 1
Design Pattern lecture 1Design Pattern lecture 1
Design Pattern lecture 1
 
jQuery
jQueryjQuery
jQuery
 
ASP.NET Lecture 5
ASP.NET Lecture 5ASP.NET Lecture 5
ASP.NET Lecture 5
 
ASP.NET lecture 8
ASP.NET lecture 8ASP.NET lecture 8
ASP.NET lecture 8
 
ASP.NET Lecture 7
ASP.NET Lecture 7ASP.NET Lecture 7
ASP.NET Lecture 7
 
ASP.NET Lecture 6
ASP.NET Lecture 6ASP.NET Lecture 6
ASP.NET Lecture 6
 
ASP.NET Lecture 4
ASP.NET Lecture 4ASP.NET Lecture 4
ASP.NET Lecture 4
 
ASP.NET Lecture 3
ASP.NET Lecture 3ASP.NET Lecture 3
ASP.NET Lecture 3
 
ASP.NET Lecture 2
ASP.NET Lecture 2ASP.NET Lecture 2
ASP.NET Lecture 2
 
AJAX and JSON
AJAX and JSONAJAX and JSON
AJAX and JSON
 
Object Oriented JavaScript
Object Oriented JavaScriptObject Oriented JavaScript
Object Oriented JavaScript
 
DOM and Events
DOM and EventsDOM and Events
DOM and Events
 

Dernier

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Dernier (20)

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

Ajax and ASP.NET AJAX

  • 1. ASP.Net AJAX JULIE ISKANDER MSc. COMMUNICATION AND ELECTRONICS
  • 2. Lecture 1 Outlines  JavaScript in ASP.NET  Adding Client-side events through ASP.NET  Fundamentals AJAX  AJAX ASP.Net  AJAX ASP.Net Controls
  • 4. JavaScript Essentials  Ways to embed JavaScript code in a web page: 1. Directly in an event attribute for an HTML element. 2. Add a <script> tag that contains the JavaScript code. 1. The code an be run automatically when the page loads 2. Inserted in a JavaScript function that will be called in response to a client-side event.  External Javascript file (.js) can be linked to a webpage using <script> tag with src attribute taking the js file url  HTML Document Object Model (DOM)  Client Side Events
  • 5. OnClientClick Property  Button, ImageButton , LinkButton  To add client-side code to the button click  If the JS code returns true postback is called  Else  postback is canceled
  • 6. Adding Clientside events through asp.net
  • 7. Rendering Script Blocks  Page.ClientScript Methods  RegisterClientScriptInclude(): This method adds a script tag that references an external js file at the top of the rendered page.  RegisterClientScriptBlock(): Writes a script block at the beginning of the web form, right after the <form runat="server"> tag  RegisterStartupScript(): Writes a script block at the end of the web form, right before the closing </form> tag
  • 8.
  • 10. AJAX  Asynchronous Javascript And Xml  Does things behind the scenes  Looks a lot more like desktop application then web applications  No need to refresh the whole page at each interaction with the server  Modifies page on the fly  JavaScript binds everything together
  • 11. Traditional Web Application Vs. AJAX Web Application  Traditional Web application
  • 12. Traditional Web Application VS. AJAX Web Application  AJAX Web application
  • 13.
  • 14. Steps to do a simple ajax request to get data 1. Create XMLHttpRequest Object 2. Open the request, set the HTTP method and URL 3. Set callback for onreadychange 4. Send asynchronous request 5. Create an event to call the previous steps All this is JAVASCRIPT Code
  • 15. 1- Creating the XMLHttpRequest Object
  • 17. readyState values Value Description 0 Uninitialized 1 Loading 2 Loaded 3 Interactive 4 Complete
  • 18. Some status values Value Description 200 Ok 204 No content 401 UnAuthorized 404 Not Found 411 Request Timeout
  • 20.
  • 21.
  • 22. Custom HTTP handler .ashx  A light-weight option as it doesn’t use the full-page model.  A class that implements IHttpHandler  void ProcessRequest(HttpContext context)  bool IsReusable
  • 25. .aspx that calls .ashx using ajax
  • 27.
  • 28.
  • 29. Ajax and Client Callbacks 1. A JavaScript event fires, triggering the server callback. 2. The normal page life cycle occurs. 3. ASP.NET executes the server-side callback method. It accepts a single string parameter and returns a single string. 4. The page receives the response from the server-side method, it uses JavaScript code to modify the web page accordingly.
  • 30. Ajax and Client Callbacks  The Page must implement ICallbackEventHandler  Must Implement  public void RaiseCallbackEvent(string eventArgument)  public string GetCallbackResult()
  • 31.
  • 32. Ajax and Client Callbacks
  • 34. ASP.NET AJAX  Successor of Atlas  Was first a separate component in ASP.NET 2.0 then become completely integrated.  ASP.NET AJAX is made up of:  ASP.NET AJAX on the Client  ASP.NET AJAX on the Server
  • 35. ASP.NET AJAX on the Client  JavaScript files, in System.Web.Extensions.dll  MicrosoftAjax.js, MicrosoftAjaxWebForms.js, and MicrosoftAjaxTimer.js.)
  • 36. ASP.NET AJAX on the Server  ScriptManager,  is the brains of the server-side ASP.NET AJAX model.  No visual appearance on the page.  renders the links to the ASP.NET AJAX JavaScript libraries.  Each page that uses ASP.NET AJAX requires an instance of the ScriptManager.  A page can has one and only one ScriptManager.
  • 38. The ASP.NET AJAX Server Controls Manages script libraries and script ScriptManager files, partial-page rendering, and other functions. Enables sections of a page to be UpdatePanel partially rendered without a page postback. Provides visual feedback on the UpdateProgress browser when the contents on UpdatePanel controls refresh. Performs partial-page updates at Timer defined intervals.
  • 39. ASP.NET AJAX Server Control  Create partial-page update  Emit the ASP.NET AJAX script needed  Disadvantage  Reduced flexibility
  • 41. ASP.NET AJAX Server Control  ScriptManager  Must be added before any other AJAX control.  Control manages the client-side scripts that enable asynchronous Ajax functionality.  Only ONE ScriptManager per page.
  • 42. ASP.NET AJAX Server Control  UpdatePanel  Isolating a section of a page for a partial-page update.  Intercept any submit event on it and call asynchronous callback to refresh it content.  Any content that’s outside the panel and changed is ignored.  UpdateMode Property is Always or Conditional  Always  updates with any partial update  Conditional  updated independently
  • 43. ASP.NET AJAX Server Control  UpdatePanel Triggers  Triggers to render UpdatePanel on event occurrence .  Triggers link controls outside the panel  To specify when an UpdatePanel should update, you need to define an UpdatePanel trigger.  AsyncPostBackTrigger  updates only UpdatePanels with UpdateMode Always and Conditional with the trigger  PostBackTrigger
  • 44. ASP.NET AJAX Server Control  Timer Control  Interval Property to set maximum number of milliseconds before next update.  If on an UpdatePanel triggers asynchronous postback  If not on one, nor linked in a trigger  causes full page postback
  • 45. ASP.NET AJAX Server Control  UpdateProgress Control  Specify some content that will appear as soon as an asynchronous request is started and disappear as soon as the request is finished.  Can include a fixed message or image.
  • 46.
  • 47. Note  When the callback is performed, the target page actually starts executing a trimmed-down life cycle.  Control events won’t execute, but the Page.Load and Page.Init event  Page.IsPostBack = true,  Page.IsCallback =true  No page rendering.  View state information is retrieved  Any changes made are not sent back to the page.  Only strings can be sent and received.
  • 48.
  • 49. Ajax Control Toolkit  http://www.asp.net/ajaxlibrary/act.ashx  Open Source toolkit for AJAX controls and extenders.  http://stephenwalther.com/blog/archive/2011/11/16 /ajax-control-toolkit-november-2011-release.aspx  Read about changes to 2011 release
  • 50.
  • 51. Lab #1  Try the lecture examples again.  Use javascript to read xml and txt files  Download Ajax control toolkit  Try lecture Examples
  • 52. References  [1] Pro ASP.NET In C# 2010, Fourth Edition,matthew Macdonald, Adam Freeman, And Mario Szpuszta, Apress  [2]Profesional ASP.NET 4 in C# and VB.NET, Bill Evjen, Scott Hanselman and Devin Rader, Wiley  [3] http://www.adaptivepath.com/ideas/ajax-new- approach-web-applications

Notes de l'éditeur

  1. The Document Object Model (DOM) is the model that describes how all elements in an HTML page, like input fields, images, paragraphs etc., are related to the topmost structure: the document itself. By calling the element by its proper DOM name, we can influence it.
  2. AddJSCode page
  3. Synchronous request
  4. Must be executed before any further interaction with the XMLHttpRequest Object
  5. XMLHttpRequestObject.responseText or responseXML
  6. Ajaxlib.jsData.txtDefault.aspxTry requestingaspx page
  7. XMLHttpRequestObject.responseText or responseXML
  8. CustomerDetailsUsingAJAX-ASHX.aspxCustomerDetail.ashx
  9. thisControl that handles the client callback, implementing ICallbackEventHandler“…….” argument passed from client script to the server RaseCallbackEvent“…..”clientcallback, name of client event handler that receives result from server“……”context, client script that is evaluated on client prior to initiating the callback.BoolAsync
  10. Putting more than one instance of the ScriptManager control on a Web Form causes the application to throw an InvalidOperationException when the page is initialized.
  11. TryMSAjaxControls.aspx
  12. Ajaxtoolkit.aspx