{"id":21,"date":"2010-09-12T20:40:23","date_gmt":"2010-09-12T16:40:23","guid":{"rendered":"http:\/\/varietysoftworks.com\/?p=21"},"modified":"2010-09-13T03:58:04","modified_gmt":"2010-09-12T23:58:04","slug":"pagerequestmanager","status":"publish","type":"post","link":"http:\/\/varietysoftworks.com\/?p=21","title":{"rendered":"PageRequestManager"},"content":{"rendered":"<p>In order to demonstrate the points I made in the previous post, I created a small program.  This turned out to be a bit more than I anticpated, which seemed to merit more explanation than I had planned. The following screen shot is created by a ListView using the jQuery alternate row styling previosly mentioned.<br \/>\n<img decoding=\"async\" loading=\"lazy\" width=\"809\" height=\"241\" class=\"alignnone size-medium wp-image-22\" src=\"http:\/\/varietysoftworks.com\/wordpress\/wp-content\/uploads\/2010\/08\/BookTest1.png\" alt=\"ListView example\" srcset=\"http:\/\/varietysoftworks.com\/wordpress\/wp-content\/uploads\/2010\/08\/BookTest1.png 809w, http:\/\/varietysoftworks.com\/wordpress\/wp-content\/uploads\/2010\/08\/BookTest1-300x89.png 300w\" sizes=\"(max-width: 809px) 100vw, 809px\" \/><\/p>\n<p><a href=\"http:\/\/varietysoftworks.com\/SourceCode\/BookTest.aspx.html\" target=\"_blank\">Here is the page code<\/a><\/p>\n<p>The ListView is at lines 48 to 103.  It has several interesting features.<\/p>\n<ol>\n<li>There is a single ItemTemplate (82-91) but notice that it has an alternating row style.  This, of course, was the original point.  This is achieved by applying the script function StyleTable() (111-114) from the Document ready script (110).<\/li>\n<li>If you simply place a ListView on the page, you will get &#8220;page flicker&#8221; when you edit and update an item.  From a coding standpoint the simplest way to eliminate this is to place the ListView in an UpdatePanel (48-49, 106-107) <\/li>\n<li>\n<p>With the UpdatePanel in place we now get nice flickerless updates &#8212; except the alternating row styling disappears. When you do a partial page update, you get partial application of styling and scripts.  In this case, the Document ready script does not fire when the page does a partial update. This is where we call on the PageRequestManager.<\/p>\n<p>The PageRequestManager code is at lines 120-128 and provides client-side events for the update panel. In this example code we are only using the EndRequestHandler (122, 126-128) to fire the StyleTable() function that is executed initially by Document ready.<\/p>\n<p>This is the code for StyleTable:<br \/>\n<code><\/p>\n<pre>\r\n115 \tfunction StyleTable() {\r\n116 \t\t$(\"table tr:odd\").addClass(\"odd\");\r\n117 \t\t$(\"table tr:even\").addClass(\"even\");\r\n119 \t}\r\n<\/pre>\n<p><\/code><\/p>\n<p>And this is the PageRequestManager code:<br \/>\n<code><\/p>\n<pre>\r\n120 \tvar pgmgr = Sys.WebForms.PageRequestManager.getInstance();\r\n121 \tpgmgr.add_beginRequest(BeginRequestHandler);\r\n122 \tpgmgr.add_endRequest(EndRequestHandler);\r\n123 \tfunction BeginRequestHandler(sender, args) {\r\n124 \t\tvar elem = args.get_postBackElement();\r\n125 \t}\r\n126 \tfunction EndRequestHandler(sender, args) {\r\n127 \t\tStyleTable();\r\n128 \t}\r\n<\/pre>\n<p><\/code><\/p>\n<p>Several items of interest here:<\/p>\n<ol>\n<li>You get an instance of the PageRequestManager using a factory method rather than a constructor.(120)<\/li>\n<li>The PageRequestManager has two events that need to be handled.(121-122) (Actually in this fairly simple example, only the endRequest event needs to be handled.)  The BeginRequestHandler Identifies which request is in process (in this case there is only one) and the EndRequestHandler takes care of any cleanup needed &#8211; like reapplying styles.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>In order to demonstrate the points I made in the previous post, I created a small program which turned out to be a bit more than I anticpated, which seemed to merit more explanation than I had planned. <a href=\"http:\/\/varietysoftworks.com\/?p=21\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,5],"tags":[],"_links":{"self":[{"href":"http:\/\/varietysoftworks.com\/index.php?rest_route=\/wp\/v2\/posts\/21"}],"collection":[{"href":"http:\/\/varietysoftworks.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/varietysoftworks.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/varietysoftworks.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/varietysoftworks.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=21"}],"version-history":[{"count":58,"href":"http:\/\/varietysoftworks.com\/index.php?rest_route=\/wp\/v2\/posts\/21\/revisions"}],"predecessor-version":[{"id":81,"href":"http:\/\/varietysoftworks.com\/index.php?rest_route=\/wp\/v2\/posts\/21\/revisions\/81"}],"wp:attachment":[{"href":"http:\/\/varietysoftworks.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=21"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/varietysoftworks.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=21"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/varietysoftworks.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=21"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}