{"id":4517,"date":"2015-08-24T08:20:49","date_gmt":"2015-08-24T08:20:49","guid":{"rendered":"http:\/\/a1webdesignteam.com\/blog\/?p=4517"},"modified":"2015-08-24T08:20:49","modified_gmt":"2015-08-24T08:20:49","slug":"asp-net-ajax-control","status":"publish","type":"post","link":"https:\/\/a1webdesignteam.com\/blog\/asp-net-ajax-control\/","title":{"rendered":"ASP.NET &#8211; Ajax Control"},"content":{"rendered":"<p>AJAX stands for Asynchronous JavaScript and XML. This is a cross platform technology which speeds up response time. The AJAX server controls add script to the page which is executed and processed by the browser.<\/p>\n<p>However like other ASP.NET server controls, these AJAX server controls also can have methods and event handlers associated with them, which are processed on the server side.<\/p>\n<p>The control toolbox in the Visual Studio IDE contains a group of controls called the &#8216;AJAX Extensions&#8217;<\/p>\n<p><img src=\"http:\/\/www.tutorialspoint.com\/asp.net\/images\/ajax_extensions.jpg\" alt=\"AJAX Extensions\" \/><\/p>\n<h2>The ScriptManager Control<\/h2>\n<p>The ScriptManager control is the most important control and must be present on the page for other controls to work.<\/p>\n<p>It has the basic syntax:<\/p>\n<pre class=\"prettyprint notranslate prettyprinted\"><span class=\"tag\">&lt;asp:ScriptManager<\/span> <span class=\"atn\">ID<\/span><span class=\"pun\">=<\/span><span class=\"atv\">\"ScriptManager1\"<\/span> <span class=\"atn\">runat<\/span><span class=\"pun\">=<\/span><span class=\"atv\">\"server\"<\/span><span class=\"tag\">&gt;<\/span>\r\n<span class=\"tag\">&lt;\/asp:ScriptManager&gt;<\/span><\/pre>\n<p>If you create an &#8216;Ajax Enabled site&#8217; or add an &#8216;AJAX Web Form&#8217; from the &#8216;Add Item&#8217; dialog box, the web form automatically contains the script manager control. The ScriptManager control takes care of the client-side script for all the server side controls.<\/p>\n<h2>The UpdatePanel Control<\/h2>\n<p>The UpdatePanel control is a container control and derives from the Control class. It acts as a container for the child controls within it and does not have its own interface. When a control inside it triggers a post back, the UpdatePanel intervenes to initiate the post asynchronously and update just that portion of the page.<\/p>\n<p>For example, if a button control is inside the update panel and it is clicked, only the controls within the update panel will be affected, the controls on the other parts of the page will not be affected. This is called the partial post back or the asynchronous post back.<\/p>\n<h3>Example<\/h3>\n<p>Add an AJAX web form in your application. It contains the script manager control by default. Insert an update panel. Place a button control along with a label control within the update panel control. Place another set of button and label outside the panel.<\/p>\n<p>The design view looks as follows:<\/p>\n<p><img src=\"http:\/\/www.tutorialspoint.com\/asp.net\/images\/scriptmanager.jpg\" alt=\"ScriptManager\" \/><\/p>\n<p>The source file is as follows:<\/p>\n<pre class=\"prettyprint notranslate prettyprinted\"><span class=\"tag\">&lt;form<\/span> <span class=\"atn\">id<\/span><span class=\"pun\">=<\/span><span class=\"atv\">\"form1\"<\/span> <span class=\"atn\">runat<\/span><span class=\"pun\">=<\/span><span class=\"atv\">\"server\"<\/span><span class=\"tag\">&gt;<\/span>\r\n   <span class=\"tag\">&lt;div&gt;<\/span>\r\n      <span class=\"tag\">&lt;asp:ScriptManager<\/span> <span class=\"atn\">ID<\/span><span class=\"pun\">=<\/span><span class=\"atv\">\"ScriptManager1\"<\/span> <span class=\"atn\">runat<\/span><span class=\"pun\">=<\/span><span class=\"atv\">\"server\"<\/span> <span class=\"tag\">\/&gt;<\/span>\r\n   <span class=\"tag\">&lt;\/div&gt;<\/span>\r\n   \r\n   <span class=\"tag\">&lt;asp:UpdatePanel<\/span> <span class=\"atn\">ID<\/span><span class=\"pun\">=<\/span><span class=\"atv\">\"UpdatePanel1\"<\/span> <span class=\"atn\">runat<\/span><span class=\"pun\">=<\/span><span class=\"atv\">\"server\"<\/span><span class=\"tag\">&gt;<\/span>\r\n      <span class=\"tag\">&lt;ContentTemplate&gt;<\/span>\r\n         <span class=\"tag\">&lt;asp:Button<\/span> <span class=\"atn\">ID<\/span><span class=\"pun\">=<\/span><span class=\"atv\">\"btnpartial\"<\/span> <span class=\"atn\">runat<\/span><span class=\"pun\">=<\/span><span class=\"atv\">\"server\"<\/span> <span class=\"atn\">onclick<\/span><span class=\"pun\">=<\/span><span class=\"atv\">\"<\/span><span class=\"pln\">btnpartial_Click<\/span><span class=\"atv\">\"<\/span> <span class=\"atn\">Text<\/span><span class=\"pun\">=<\/span><span class=\"atv\">\"Partial PostBack\"<\/span><span class=\"tag\">\/&gt;<\/span>\r\n         <span class=\"tag\">&lt;br<\/span> <span class=\"tag\">\/&gt;<\/span>\r\n         <span class=\"tag\">&lt;br<\/span> <span class=\"tag\">\/&gt;<\/span>\r\n         <span class=\"tag\">&lt;asp:Label<\/span> <span class=\"atn\">ID<\/span><span class=\"pun\">=<\/span><span class=\"atv\">\"lblpartial\"<\/span> <span class=\"atn\">runat<\/span><span class=\"pun\">=<\/span><span class=\"atv\">\"server\"<\/span><span class=\"tag\">&gt;&lt;\/asp:Label&gt;<\/span>\r\n      <span class=\"tag\">&lt;\/ContentTemplate&gt;<\/span>\r\n   <span class=\"tag\">&lt;\/asp:UpdatePanel&gt;<\/span>\r\n   \r\n   <span class=\"tag\">&lt;p&gt;<\/span><span class=\"pln\">\u00a0<\/span><span class=\"tag\">&lt;\/p&gt;<\/span>\r\n   <span class=\"tag\">&lt;p&gt;<\/span><span class=\"pln\">Outside the Update Panel<\/span><span class=\"tag\">&lt;\/p&gt;<\/span>\r\n   <span class=\"tag\">&lt;p&gt;<\/span>\r\n      <span class=\"tag\">&lt;asp:Button<\/span> <span class=\"atn\">ID<\/span><span class=\"pun\">=<\/span><span class=\"atv\">\"btntotal\"<\/span> <span class=\"atn\">runat<\/span><span class=\"pun\">=<\/span><span class=\"atv\">\"server\"<\/span> <span class=\"atn\">onclick<\/span><span class=\"pun\">=<\/span><span class=\"atv\">\"<\/span><span class=\"pln\">btntotal_Click<\/span><span class=\"atv\">\"<\/span> <span class=\"atn\">Text<\/span><span class=\"pun\">=<\/span><span class=\"atv\">\"Total PostBack\"<\/span> <span class=\"tag\">\/&gt;<\/span>\r\n   <span class=\"tag\">&lt;\/p&gt;<\/span>\r\n   \r\n   <span class=\"tag\">&lt;asp:Label<\/span> <span class=\"atn\">ID<\/span><span class=\"pun\">=<\/span><span class=\"atv\">\"lbltotal\"<\/span> <span class=\"atn\">runat<\/span><span class=\"pun\">=<\/span><span class=\"atv\">\"server\"<\/span><span class=\"tag\">&gt;&lt;\/asp:Label&gt;<\/span>\r\n<span class=\"tag\">&lt;\/form&gt;<\/span><\/pre>\n<p>Both the button controls have same code for the event handler:<\/p>\n<pre class=\"prettyprint notranslate prettyprinted\"><span class=\"kwd\">string<\/span><span class=\"pln\"> time <\/span><span class=\"pun\">=<\/span> <span class=\"typ\">DateTime<\/span><span class=\"pun\">.<\/span><span class=\"typ\">Now<\/span><span class=\"pun\">.<\/span><span class=\"typ\">ToLongTimeString<\/span><span class=\"pun\">();<\/span><span class=\"pln\">\r\nlblpartial<\/span><span class=\"pun\">.<\/span><span class=\"typ\">Text<\/span> <span class=\"pun\">=<\/span> <span class=\"str\">\"Showing time from panel\"<\/span> <span class=\"pun\">+<\/span><span class=\"pln\"> time<\/span><span class=\"pun\">;<\/span><span class=\"pln\">\r\nlbltotal<\/span><span class=\"pun\">.<\/span><span class=\"typ\">Text<\/span> <span class=\"pun\">=<\/span> <span class=\"str\">\"Showing time from outside\"<\/span> <span class=\"pun\">+<\/span><span class=\"pln\"> time<\/span><span class=\"pun\">;<\/span><\/pre>\n<p>Observe that when the page is executed, if the total post back button is clicked, it updates time in both the labels but if the partial post back button is clicked, it only updates the label within the update panel.<\/p>\n<p><img src=\"http:\/\/www.tutorialspoint.com\/asp.net\/images\/update_panel.jpg\" alt=\"update panel\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>AJAX stands for Asynchronous JavaScript and XML. This is a cross platform technology which speeds up response time. The AJAX server controls add script to the page which is executed and processed by the browser. However like other ASP.NET server controls, these AJAX server controls also can have methods and event handlers associated with them, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4518,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0},"categories":[32],"tags":[51],"_links":{"self":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts\/4517"}],"collection":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/comments?post=4517"}],"version-history":[{"count":0,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/posts\/4517\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/media\/4518"}],"wp:attachment":[{"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/media?parent=4517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/categories?post=4517"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/a1webdesignteam.com\/blog\/wp-json\/wp\/v2\/tags?post=4517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}