<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="html">tips - Mr. Roa</title>
  <icon>http://mrroa.com/Content/icons/mushroom.ico</icon>
  <logo>http://mrroa.com/Content/icons/mushroom.png</logo>
  <updated>2010-07-20T00:46:00</updated>
  <subtitle type="html">The name is Roa. Mr. Roa</subtitle>
  <id>http://mrroa.com/tags/tips/atom</id>
  <link rel="alternate" type="text/html" hreflang="en" href="/tags/tips/atom"/>
  <link rel="self" type="application/atom+xml" href="http://mrroa.com/Tags/tips/ATOM"/>
  <generator uri="http://oxite.net" version="1.0">Oxite</generator>
  <entry>
    <title type="html">TIP/Trick: Use DataPager control with ListView and Custom Data Source</title>
    <link rel="alternate" type="text/html" href="http://mrroa.com/Blog/TIPTrick-Use-DataPager-control-with-ListView-and-Custom-Data-Source"/>
    <id>http://mrroa.com/Blog/TIPTrick-Use-DataPager-control-with-ListView-and-Custom-Data-Source</id>
    <updated>2010-07-21T01:35:43.96</updated>
    <published>2010-07-20T00:46:00</published>
    <author>
      <name>Admin</name>
    </author>
    <category term="tips" />
    <category term="datapager" />
    <category term="listview" />
    <content type="html" xml:lang="en">
      &lt;p&gt;Paging tabular data retrieved through a database query has been a long time need in transactional line of business applications. With time the ways of achieving this in ASP .NET have evolved into very easy solutions. On the previous version of the framework, .NET framework 3.5 (currently to the date they are now on 4.0) two server-side user controls where introduced, the ListView and the DataPager.&lt;/p&gt;
&lt;p&gt;They idea behind the ListView control is to provide the developer with more control over the markup output while providing the data-bound experience of previous controls. The ListView control displays data based on user defined templates, which is extremely convenient for styling purposes. It also reduces to zero the garbage markup automatically generated by older controls like the GridView.&lt;/p&gt;
&lt;p&gt;The DataPager, in the other hand, is product of the decoupling of the paging feature from the data-bound controls that implement the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.ipageableitemcontainer.aspx&quot; target=&quot;_blank&quot;&gt;IPageableItemContainer&lt;/a&gt; interface. Providing more freedom when it comes to paging&amp;nbsp;customization on regards of&amp;nbsp;functionality&amp;nbsp;and appearance.&lt;/p&gt;
&lt;p&gt;Both controls complement each other in a marvelous way. The DataPager provides paging&amp;nbsp;practically&amp;nbsp;out of the box when using a data source control, which is what the documentation found almost everywhere encourages to use. BUT! The truth is that sometimes we use custom data sources because of a special scenario that dictates their use to get the data. In this scenario is were the use of the DataPager becomes a little bit more challenging, since the paging is once more a developer's responsibility rather than a delegated feature for the framework.&lt;/p&gt;
&lt;h3&gt;So how do we tackle this?&lt;/h3&gt;
&lt;p&gt;One approach is raising and handling the &lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.templatepagerfield.pagercommand.aspx&quot; target=&quot;_blank&quot;&gt;PagerCommand&lt;/a&gt; event found on the DataPager&amp;nbsp;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.templatepagerfield.aspx&quot; target=&quot;_blank&quot;&gt;TemplatePagerField&lt;/a&gt; template and evaluating each command sent from the server-side controls placed there. This is extremely convenient if you want to implement a custom way of paging the data and navigating through it. You'll also have the&amp;nbsp;responsibility&amp;nbsp;of rendering the current page you're at, as well as all the other available navigation pages.&lt;/p&gt;
&lt;p&gt;Another approach, and the one we'll describe with more depth, is a little bit more simple and similar to the default behavior of the DataPager when used with data source controls. For this we just need to raise the ListView's&amp;nbsp;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.pagepropertieschanging.aspx&quot; target=&quot;_blank&quot;&gt;PagePropertiesChanging&lt;/a&gt; event and invoke the DataPager's&amp;nbsp;&lt;a href=&quot;http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datapager.setpageproperties.aspx&quot; target=&quot;_blank&quot;&gt;SetPageProperties&lt;/a&gt; method. This is an obvious combination since the&amp;nbsp;PagePropertiesChangingEventArgs provide us the arguments of the SetPageProperties method overload.&lt;/p&gt;
&lt;h3&gt;The code&lt;/h3&gt;
&lt;p&gt;I think we've done enough to describe what we are trying to achieve here, so let's see the code for this. Let's asume we have a ListView called lvProducts.&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;protected void lvProducts_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
{
&amp;nbsp;&amp;nbsp; &amp;nbsp;var pager = (DataPager)lvProducts.FindControl(&quot;pager&quot;); //pager is the name of our DataPager control

&amp;nbsp;&amp;nbsp; &amp;nbsp;pager.SetPageProperties(

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;e.StartRowIndex,&amp;nbsp;

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;e.MaximumRows,&amp;nbsp;

&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;false); //Set false because we are using a custom data source

&amp;nbsp;&amp;nbsp; &amp;nbsp;BindDataToListView(); //Here we just bind the data to our list view again and the new data page will be displayed
}&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And that's it! Paging should work like a charm. Happy coding!&lt;/p&gt;
    </content>
  </entry>
  <entry>
    <title type="html">TIP/Trick: Enable/Disable ASP .NET Ajax TabContainer Tabs</title>
    <link rel="alternate" type="text/html" href="http://mrroa.com/Blog/TIPTrick-EnableDisable-ASP-NET-Ajax-TabContainer-Tabs"/>
    <id>http://mrroa.com/Blog/TIPTrick-EnableDisable-ASP-NET-Ajax-TabContainer-Tabs</id>
    <updated>2010-04-27T05:31:08.663</updated>
    <published>2009-12-01T14:20:00</published>
    <author>
      <name>Admin</name>
    </author>
    <category term="jquery" />
    <category term="tips" />
    <category term="ajax" />
    <category term="tabs" />
    <content type="html" xml:lang="en">
      &lt;p&gt;Space and content distribution is a very important part when designing a web site. That's why breaking content into multiple sections using a tabbed widget in order to save space is a commonly used technique in web design these days.&lt;/p&gt;
&lt;p&gt;Today I'm going to address a common issue that arises when using a tab widget, which is enabling/disabling specific tabs. But first let's talk a little bit about the &lt;a href=&quot;http://www.asp.net/ajax/AjaxControlToolkit/Samples/&quot; target=&quot;_blank&quot;&gt;Ajax Control Toolkit&lt;/a&gt;. The Ajax Control Toolkit provides a palette of AJAX enabled controls, with the purpose of creating an &quot;interactive web experience&quot;. If you work with ASP .NET, you MUST have heard about &lt;a href=&quot;http://www.asp.net/ajax/&quot; target=&quot;_blank&quot;&gt;ASP .NET AJAX&lt;/a&gt;, previously known as ATLAS. You must also have seen and feel familiar with update panels and Microsoft's ASP .NET AJAX paradigm. Certainly the ASP .NET AJAX framework makes AJAX implementation trivial to anyone.&lt;/p&gt;
&lt;p&gt;The tendency of throwing update panels everywhere in order to achieve partial post backs in your page it's a widely used approach among ASP .NET AJAX enabled sites. It's also a common practice to see how every server/client side control on a web page, get replaced with any equivalent found on the AJAX Toolkit provided by Microsoft. If you are using one of these &quot;cutting edge&quot; techniques my friend, let me tell you that you are killing your application performance. And that also, I'm NOT the first one to point this out. The ASP .NET AJAX framework and the AJAX Toolkit have been widely criticized over thousands of technical web blogs. Mainly because by providing a mechanism for &quot;easy&quot; AJAX implementation performance of your web application gets compromised.&lt;/p&gt;
&lt;p&gt;Basically,&amp;nbsp;performance get
&lt;script src=&quot;../../../Skins/Default/Scripts/tiny_mce/themes/advanced/langs/en.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;../../../Skins/Default/Scripts/tiny_mce/themes/advanced/langs/en.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
s affected because a lot of web resources get imported when using both the framework and the toolkit. Also the fact that in every &quot;partial post back&quot; you actually send the whole page making HTTP GET/POST actions more bloated when loading your page. You could use Mozilla Firefox's Firebug plugin to analyze your HTTP requests and the amount of data that gets sent back and forth to the server, or just google about the topic in order to extend your knowledge about this particular subject.&lt;/p&gt;
&lt;p&gt;I encourage you guys to use other lightweight javascript frameworks that help you achieve DOM manipulation and asynchronous calls to the server in order to retrieve and send data like &lt;a href=&quot;http://www.jquery.com/&quot; target=&quot;_blank&quot;&gt;jQuery&lt;/a&gt; or &lt;a href=&quot;http://www.prototypejs.org/&quot; target=&quot;_blank&quot;&gt;Prototype&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;Show me the code!&lt;/h3&gt;
&lt;p&gt;So I decided to do two examples instead of one. Besides doing it using the AJAX Control Toolkit. I also did it using jQuery, just to have two options. So here's the code.&lt;/p&gt;
&lt;h4&gt;AJAX Control Toolkit Tab Container&lt;/h4&gt;
&lt;p&gt;Here's the HTML:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&amp;lt;div style=&quot;width: 500px&quot;&amp;gt;
  &amp;lt;cc1:TabContainer ID=&quot;TabContainer1&quot; runat=&quot;server&quot;&amp;gt;
      &amp;lt;cc1:TabPanel Hea&lt;script src=&quot;../../../Skins/Default/Scripts/tiny_mce/themes/advanced/langs/en.js&quot; type=&quot;text/javascript&quot;&gt;&lt;!--mce:2--&gt;&lt;/script&gt;derText=&quot;Tab 1&quot; runat=&quot;server&quot; ID=&quot;tpTab1&quot;&amp;gt;
          &amp;lt;ContentTemplate&amp;gt;
                Tab 1 Content!
          &amp;lt;/ContentTemplate&amp;gt;
      &amp;lt;/cc1:TabPanel&amp;gt;
      &amp;lt;cc1:TabPanel HeaderText=&quot;Tab 2&quot; runat=&quot;server&quot; ID=&quot;tpTab2&quot;&amp;gt;
          &amp;lt;ContentTemplate&amp;gt;
                Tab 2 Content!
          &amp;lt;/ContentTemplate&amp;gt;
      &amp;lt;/cc1:TabPanel&amp;gt;
  &amp;lt;/cc1:TabContainer&amp;gt;
  &amp;lt;p&amp;gt;
      &amp;lt;input type=&quot;button&quot; onclick=&quot;javascript:DisableEnableTab(false,0);&quot; value=&quot;Disable Tab 1&quot; /&amp;gt;
  &amp;lt;/p&amp;gt;         
&amp;lt;/div&amp;gt;
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And here's the javascript:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;function DisableEnableTab(boolVal, tabIndex) {
      var tab = $find('&amp;lt;%=TabContainer1.ClientID%&amp;gt;');
      tab.get_tabs()[tabIndex].set_enabled(boolVal);
}
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;h3&gt;jQuery&lt;/h3&gt;
&lt;p&gt;Here's the HTML:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;&amp;lt;div id=&quot;tabs&quot; style=&quot;width: 500px&quot;&amp;gt;
      &amp;lt;ul&amp;gt;
          &amp;lt;li&amp;gt;&amp;lt;a href=&quot;#tab-1&quot;&amp;gt;&amp;lt;span&amp;gt;One&amp;lt;/span&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
          &amp;lt;li&amp;gt;&amp;lt;a href=&quot;#tab-2&quot;&amp;gt;&amp;lt;span&amp;gt;Two&amp;lt;/span&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
      &amp;lt;/ul&amp;gt;
      &amp;lt;div id=&quot;tab-1&quot;&amp;gt;
          Tab 1 Content!
      &amp;lt;/div&amp;gt;
      &amp;lt;div id=&quot;tab-2&quot;&amp;gt;
          Tab 2 Content!
     &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;p&amp;gt;
   &amp;lt;input type=&quot;button&quot; onclick=&quot;javascript:DisableTab();&quot; value=&quot;Disable Tab 1&quot; /&amp;gt;
&amp;lt;/p&amp;gt;
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;And here's the javascript:&lt;/p&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;$(document).ready(function() {
      $(&quot;#tabs&quot;).tabs();
 });
            
 function DisableTab() {
       //Selecting another tab
      $(&quot;#tabs&quot;).tabs('select', 1);
                
      //Disabling first tab
      $(&quot;#tabs&quot;).tabs('option', 'disabled', [0]);
 }
&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So there it is, happy coding!&lt;/p&gt;
    </content>
  </entry>
</feed>
