On October 23rd, 2014, we updated our
By continuing to use LinkedIn’s SlideShare service, you agree to the revised terms, so please take a few minutes to review them.
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
Traditional Web Application Vs. AJAX Web Application Traditional Web application
Traditional Web Application VS. AJAX Web Application AJAX Web application
Some status valuesValue Description200 Ok204 No content401 UnAuthorized404 Not Found411 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 The Page must implement ICallbackEventHandler Must Implement public void RaiseCallbackEvent(string eventArgument) public string GetCallbackResult()
Ajax and Client Callbacks
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
The ASP.NET AJAX Server Controls Manages script libraries and scriptScriptManager files, partial-page rendering, and other functions. Enables sections of a page to beUpdatePanel partially rendered without a page postback. Provides visual feedback on theUpdateProgress browser when the contents on UpdatePanel controls refresh. Performs partial-page updates atTimer defined intervals.
ASP.NET AJAX Server Control Create partial-page update Emit the ASP.NET AJAX script needed Disadvantage Reduced flexibility
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
References  Pro ASP.NET In C# 2010, Fourth Edition,matthew Macdonald, Adam Freeman, And Mario Szpuszta, Apress Profesional ASP.NET 4 in C# and VB.NET, Bill Evjen, Scott Hanselman and Devin Rader, Wiley  http://www.adaptivepath.com/ideas/ajax-new- approach-web-applications