Friday, April 8, 2011

How HTML5 will kill the native app

How HTML5 will kill the native app: "

Over the past two decades, the mobile industry has become increasingly stunted by fragmented protocols, standards, and regional differences. But a hot new technology called HTML5 promises to remedy this by delivering an unprecedented open, democratic and wonderfully fertile mobile web.


Evangelists say the HTML5 movement has so much momentum that it could defeat the native app — an application that is designed to run on a single platform — in as little as two years.


Sundar Pichai, who leads Google’s HTML5-happy Chrome OS initiative,  agrees that the “incredible advantages of the Web will prevail” over the dominant native app model. Another mobile developer expert Mike Rowehl adds: “We’ll forget that we even passed through another era of native apps on the way to the mobile web.”


The transition comes at a time when the mobile revolution is driving economic growth in the US and abroad. Phones are quickly become our second brain, and users are snapping the smartest phones they can find. Companies, large and small, are investing billions of dollars to create a smartphone presence.


HTML5 heralds huge efficiencies for web publishers, because it lets companies develop once and distribute across any device via an Internet browser. An HTML5 triumph will not only save billions in development costs, but it will also allow publishers to direct those savings towards more innovative, productive projects.


HTML5 apps are searchable by crawlers such as Google’s search engine, ensuring that the apps can be discovered by billions of consumers. They can mash content with data or apps from third parties, and access analytical services such as traffic measurement tools, and ad server targeting technologies. You don’t need to get anyone’s permission to distribute an HTLM5 app. And to top it off, at least one study says consumers prefer the convenience of them (though the research was commissioned by Adobe, which is partial to web apps).


HTML5 is so-called because it is the fifth generation of HyperText Markup Language, which is the coding language used to create web pages. By distributing over a web browser via fast, new mobile networks, HTML5 gets to bypass much of a phone’s underlying “iron,” or the chips, graphical cards and other components — all things that native apps rely on. Most phones being sold today have modern browsers that will operate on super fast 4g or LTE networks — the sort of thing that the HTML5 technology needs to thrive. Thus, as HTML5 advances (developers are working hard to improve it), companies will no longer need to build native apps.


So there’s tremendous logic behind HTML5’s onslaught. Opponents, of course, say it’s not an assured victory. HTML5 has some limitations on things like speed, and access to certain phone features such as bluetooth. What happens over the next 12 months, however, will say a lot about its chances. Its destiny primarily depends on the next steps by Apple, the biggest proponent of native apps, and thus the antagonist of this story. And  precisely because no one knows how this will play out that makes this drama so riveting: Apple is like the Joker in the Dark Knight, a fiend with flair and with a knack for eternal comebacks, while Batman (Google) works to keep the mobile metropolis safe.


(This debate about the emergence of HTML5, and its promise of a future beyond fragmented native app platforms is the focus of one of the sessions at the VentureBeat Mobile Summit April 25/26, a conference for the 180 executives active in transforming the mobile industry. Folks like Google’s Pichai, will be in attendance, as will the major carriers and CEOs of the most disruptive private companies.)


The story started in 2007, with the release of the first iPhone. Led by its enigmatic leader Steve Jobs, Apple gave developers their first real taste of independence from the carrier oligarchy. The iPhone’s beauty was manifold, but first and foremost, it allowed developers to build applications and sell them for a fee — to users who could conveniently tap their iTunes account to buy things through the iPhone’s App Store. This bypassed the control of the carriers, which had long dictated what phones featured on their “decks.”


By the time the dust began to settle, Apple had stolen a two-year lead. Not only that, millions of developers have invested in learning Objective-C, Apple’s programming framework for the iPhone, and other developer tools; these developers become specialists with vested interest to stay loyal to Apple. Now, well into 2011, Apple keeps pushing efforts to make native apps more attractive than HTLM5 web ones, in an effort to keep those millions of developers — and thus users — hostage.


And so paradoxically, Apple has turned out to be controlling, closed and manipulative. It has no incentive to push to full democracy on the web front. It is enjoys huge profits from its position, not only because it gets a 30 percent cut of the revenue from downloaded apps, but because its phones, and now iPads, are selling like crazy. It is now one of the most valuable companies in the world. At every turn, it seems, Apple finds a way to hamper or limit the features that allow HTML5 to work efficiently on its devices. It remains to be seen what tricks it has up its sleeve going forward, but it’s true that many people think Apple will be be able to stay ahead. There are so many areas where Apple and other companies have hived off their own platforms from the Web that Wired last year declared that the “Web is dead.”


But if you look closely, despite the Apple/Joker’s continued pranks to keep native app alive, you’ll see how much Google/Batman keeps closing the gap on him. The following are the areas where native app gained a quick advantage over HTML5. Note that in almost all areas HTMl5 has caught up. In several areas, HTML is about to catch up. In a few areas, HTML5 has a plan to catch up, but is admittedly at least a year or two away from doing so:



  • Touch/gestural interfaces — Gestural technology has been implemented by HTML5 framework vendors, such as Sencha. UI components that are controlled by  touch and swipe, such as carousels, scrolling lists, disclosure panels and related widgets are all supported on the HTML5 web. Vendors like Sencha are also helping get rid of things like back buttons, refresh buttons, passed links, bookmarks and other “anachronistic” features of the desktop web that don’t translate well onto the mobile web. Thus coding time has been cut down too.

  • Visual Scale — There’s nothing here that HTML5 can’t address. The web page now has sufficient ways to ask what size screen its on, and size images and resolutions accordingly.

  • Video/Audio — Now addressed by HTML5 for sustained playback. Audio synchronization for short sound effects still needs work in the browsers.

  • Graphics & FX — Native apps are faster for some operations – particularly anything very graphics-intensive. Graphic-intensive games won’t render as effectively in HTML5 anytime soon. However, increasingly, vendors like Sencha are working around many of the speed issues by doing things like embedding a map component that can be primed for loading maps — addressing the slowness you’ve seen in things like Google maps or other sites.

  • Camera/Video access — HTLM5 can handle photo capture from a web page on Android devices (at least on the latest versions, run by the Honeycomb OS; but it can’t handle it on iPhones yet).

  • Contacts access — Here, HTLM5 addresses file access, but most apps are beginning to draw from the cloud anyway, and not from the device client.

  • Accelerometer access – HTML5 can handle this.

  • Bluetooth access — This is one device access feature HTML5 has not addressed yet. That said, even for native apps, bluetooth access is fairly limited

  • Disconnected Operation — Web apps through HTML5 can now work in disconnected mode; you can get up to 50MB of database space if you ask user permission, in order to keep operating without an internet connection.

  • App Store Services (discovery, updates, payments & trust) — Not only can HTML5 apps be sold through HTML5 or Chrome app stores, they can be sold directly through Apple’s App Store, Android Marketplace or Blackberry App World, after being placed in a simple “native” app shell such as Nimblekit or Webworks.

  • Running in the background and sending notifications – There are HTLM5 specs for these capabilities, but they haven’t been implemented in the leading browsers yet. When placed in a native wrapper, HTLM5 can do this, but it still means it can’t do this without extra help.

  • Business model – Ad revenue works well on HTML5, since the mobile web already has ad networks.  But ads aren’t doing as well on mobile as many expected, so other monetization methods are necessary, such as payment technologies for subscriptions or virtual goods. For HTLM5, there are PayPal and Google APIs, but the experience isn’t very good. Lately, however, companies like Zong and Boku are making payments dead simple for the mobile web.


To conclude, native apps are still extremely popular for many developers, because HTLM5 is still working to close the performance gap. Take Trulia, the company that offers real estate information online. It’s not a game company, and so theoretically doesn’t need the blazing speed offered by a phone’s underlying chip iron. Still, mobile is a significant portion of the company’s traffic (20 percent and growing) and it’s map-heavy– and HTLM5 can’t handle the intensity of map graphics as well as native can.


Chief executive Pete Flint told me he hired ten developers to make native apps, and those apps have shown far superior engagement and page views, he says. “As a brand publisher, I’m loathe to create native apps,” he told me, “it just adds massive overhead.” Indeed, those developers need to learn specific skills to building native mobile apps, arguably having nothing to do with his core business. They have to learn the different programming code, simulators and tech capabilities of each platform, and of each version of the platform. By diverting so much money into this, he’s having to forgo investment in other core innovation. (do the back-of-the-envelope math: at least $100,000 per developer, or a total $1 million investment). In an ideal world, Flint says, he’d have embraced the evolution to HTLM5 Web apps — but HTML5 is just not there yet.


But HTLM5 will emerge competitive on just about every level within two years, says Michael Mullany, chief executive of Sencha, adding that already 95 percent of the functionality of native apps is being delivered by HTML5. And if you have any doubts about this, he points to the story already played out on the PC web. For at least 15 years, developers have been able to create “better apps” on the Windows PC desktop, compared to what they can do on a web browser. “But when was the last killer Windows native app developed?,” Mullany asks. It was probably Microsoft Outlook, which came out in 1998, he says. “Native has always had a performance advantage on the desktop,” he says, “but it hasn’t mattered because of the other benefits of being on the web.”


HTLM5 graphics performance for fast-moving games that have a lot of animation can’t match native’s performance, and probably won’t for some time to come. But for pretty much anything else, HTLM5 is good enough, an increasing number of developers are saying (see this great review by Redfin’s Sasha Aickin). The benefits gained from a slightly faster native experience will be so marginal for the vast majority of apps that it just wont’t matter enough to forgo the considerable benefits of the open web.


Things are moving very quickly. In just the past month or so, HTLM5 has shown momentum in other areas: The main browsers, from Chrome to Firefox to Explorer have bolstered their support of the web framework. Facebook, one of the fastest growing companies, and most popular companies in mobile, has largely embraced HTML5, but is expected to say more soon at its f8 conference. Enterprise players are realizing its advantages, too. Slow to embrace the smartphone native app, they’re now balking at the cost of developing those apps, especially now that Microsoft-Nokia is offering yet another compelling alternative to iOS, Android (we’ll talk another time about how Google is like Two-Face, sometimes), Palm’s WebOS and RIM — why even deal with the splintered distribution each each app would have? After all, many companies have already spent decades developing web apps for the PC, and so they don’t want to start over with native mobile apps. So some enterprise companies are embracing HTLM5 apps instead. Sencha says it saw its business double last year, largely because of this trend. Finally, publishers are getting pissed off at Apple’s insistence to retain 30 percent of the revenue from apps sold through it’s store.


This story is still in suspense stage: We just don’t know when it will end, but we do know it will end. The logic behind HTLM5 is just too compelling for native to win, but at the same time we just don’t now how many more tricks the Joker has up his sleeves to stave off this inevitable tidal shift to an open, democratic metropolis.


Tags: ,


Companies: , ,


People:
















"

Friday, April 1, 2011

Making Web Apps Sizzle with Bing Maps and HTML5’s Geolocation API

Making Web Apps Sizzle with Bing Maps and HTML5’s Geolocation API: "

A few weeks ago, I wrote about Silverlight for Windows Phone’s location API, which allows applications to ascertain their location – latitude, longitude, altitude (if GPS is available), and so on. More recently, I’ve been writing samples around HTML5’s geolocation API. The two APIs are remarkably similar save for HTML5’s lack of support for setting movement thresholds. Both allow you to write location-aware apps with remarkably little code, and both can be combined with Bing Maps to produce stunning UIs pinpointing a user’s location, providing turn-by-turn directions, and more. In fact, once you learn one of the location APIs, you’ll feel right at home with the other. They’re that much alike.

To demonstrate how to combine HTML5 geolocation with Bing Maps, I wrote a sample that I call MapLocation.html. Here it is in IE9, with a pushpin directly over my house:

BingMaps

Here’s the source code for the page, minus the Bing Maps API key that you must register for before using Bing Maps controls and services:

 

<!DOCTYPE html>

<html>

<head>

<style type="text/css">

body {

    margin: 0;

    height: 100%;

    background-color: #404040;

}

#map {

     position: absolute;

    top: 50%;

    left: 50%;

    width: 800px;

    height: 600px;

    margin-left: -400px;

    margin-top: -300px;

}

</style>

 

<script charset="UTF-8" type="text/javascript"

  src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0">

</script>

 

<script type="text/javascript" src="jquery.js"></script>

 

<script type="text/javascript">

    var _map;

 

    $(document).ready(function () {

        // Create a Bing map

        _map = new Microsoft.Maps.Map(document.getElementById("map"),

            { credentials: "Insert Bing Maps API key here" });

 

        // Get the current position from the browser

        if (!navigator.geolocation)

            alert("This browser doesn't support geolocation");

        else

            navigator.geolocation.getCurrentPosition(onPositionReady, onError);

    });

 

    function onPositionReady(position) {

        // Apply the position to the map

        var location = new Microsoft.Maps.Location(position.coords.latitude,

            position.coords.longitude);

        _map.setView({ zoom: 18, center: location });

 

        // Add a pushpin to the map representing the current location

        var pin = new Microsoft.Maps.Pushpin(location);

        _map.entities.push(pin);

    }

 

    function onError(err) {

        switch (err.code) {

            case 0:

                alert("Unknown error");

                break;

            case 1:

                alert("The user said no!");

                break;

            case 2:

                alert("Location data unavailable");

                break;

            case 3:

                alert("Location request timed out");

                break;

        }

    }

</script>

</head>

<body>

 

<div id="map" />

 

</body>

</html>

 

So how does it work? First, I point a <script> element to http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0, which is home for the new Bing Maps AJAX control, version 7.0. Then I instantiate a Microsoft.Maps.Map object (the map) and insert it into the DIV named “map.” Next, I call HTML5’s navigator.geolocation.getCurrentPosition to get the latitude and longitude of my current location. When that call completes, I call setView on the map control, passing in the latitude and longitude provided by getCurrentPosition. For good measure, I create a pushpin at the same location so my current location is called out on the map. Not a lot of code, but a WHOLE lot of results!

Here’s what I found most surprising about this exercise. Testing it on my desktop PC, I wasn’t sure if the geolocation API would work. Even if it did work, I expected the accuracy to be low since the location data would have to come from Wi-fi positioning. In most browsers, the accuracy is good to within a few hundred feet. In IE9, it’s so accurate, it pinpointed the location of the router in my house! Most browsers, I believe, use a positioning service provided by Google to convert IP addresses into locations. (I know that’s true of Opera, because the first time an app running in Opera requests a location, Opera pops up a dialog and asks you to agree to Google terms and conditions.) IE9 evidently uses something different, which isn’t surprising given that Microsoft probably wouldn’t care to make their flagship browser dependent on anything Google provided. Whatever Microsoft is using, it’s amazingly accurate. Of course, your mileage may vary.

It’s pretty cool to know that with HTML5, you can write browser-based apps that, for example, use your current location to show nearby restaurants, movie theatres, and stores. But what’s even more alluring is the thought of building mobile apps that work across a range of devices. If I use Silverlight for Windows Phone to write a location-aware app, it only works on Windows phones. But if I use HTML5, it should work on iPhones, iPads, and even on Android devices. Once Windows Phone 7 acquires an HTML5 browser, it’ll work there, too.

Even HTML5 doesn’t insulate you from all the annoying differences between browsers; I still find myself spending way too much time trying to get something that works fine in Firefox working in IE9, too, or vice versa. But the geolocation API is so simple that there’s not a lot to break going from one browser to another. That’s good news for developers, and good news for consumers as well.

"

Tuesday, March 29, 2011

Master-Detail with the GridView, DetailsView and jQuery's ThickBox

Master-Detail with the GridView, DetailsView and jQuery's ThickBox: "

And so I continue on messing around with jQuery and looking into ways I can use it in my WebForms applications.  Something I sheepishly admitted to in my last post was that I don't want to use 3 client side libraries {ASP.NET AJAX, AjaxControlToolkit, jQuery}, yet I never really took the time to see what the size of the core jQuery library is.  And for that matter I haven't really looked at what scripts some of my favorite AjaxControlToolkit controls are pulling down either.  I also assumed there is a bunch of overlap between jQuery and ASP.NET AJAX, but I haven't looked into that either. 

So I thought I would check some of this out and along the way rebuild my Master-Detail with the GridView, DetailView and ModalPopup Controls and replace the ModalPopup with jQuery's ThickBox.  I found it pretty interesting - read on to see how it went.

Live Demo | Download

ThickBox Demo

What I Was Looking For

While building this sample I decided I would keep my eye out for the following things ...

  1. Size Comparison (minified, but not gzipped) of AjaxControlToolkit's ModalPopup versus jQuery's ThickBox
  2. Installation / Configuration 
  3. Programming Model / API 
  4. ASP.NET AJAX Integration 

 

jQuery's ThickBox

If you are not familiar with jQuery's ThickBox = here the 2 sentence description taken from the ThickBox home page ...

ThickBox is a webpage UI dialog widget written in JavaScript on top of the jQuery library.  Its function is to show a single image, multiple images, inline content, iframed content, or a content server through AJAX in a hybrid model

Size Comparison

This is what I was most interested in.  I get a lot of comments to my AjaxControlToolkit posts that comment on how large the client side footprint of the Toolkit is.  And I honestly don't really know how to respond - mostly because I don't have a baseline that I can compare it to.  And jQuery's ThickBox and the Toolkit's ModalPopup is not exactly like comparing apples to apples, but I think it is close enough to get a feeling for things.

So here are the numbers ...

 FileSize (Compressed)
ThickBox  
 jQuery.js55KB
 ThickBox.js/ThickBox.css10KB
Total 65KB
ModalPopup  
 Common.js28KB
 BaseScripts.js11KB
 RoundedCornersBehavior.js27KB
 Timer.js1KB
 DropShadowBehavior.js7KB
 DynamicPopulateBehavior.js6KB
 DragDropScripts.js23KB
 DynamicPopulateBehavior.js6KB
 Floatingehavior.js4KB
 ModalPopupBehavior.js18KB
Total 131KB

 

The ModalPopup and its supporting scripts is just over twice the size of the jQuery plus ThickBox combo.  Interesting.  If you are curious about where I got the numbers from - I used the file system to get the jQuery/ThickBox numbers and Reflector to look at the sizes of the Toolkit's supporting JavaScript files (they are embedded resources). 

image

I should mention though that although both the ModalPopup and ThickBox JavaScript files are both minified - this wasn't done with the same tool.  And to my novice eye, it looks like the one jQuery uses does a better job.  So you should keep this in mind when interpreting these numbers.  Also, this is without gzipping - so these numbers will both be smaller after this is applied as well.

 

ThickBox Installation and Configuration

If you want to use the ThickBox, you have to do the following things ...

1.  Download the latest version of jQuery and add a script reference to your page

2.  Download thickbox.js, thickbox-compressed.js, thickbox.css and the loadingAnimation.gif graphic and place them in your web site.  I included both the compressed and non-compressed versions of thickbox just in-case I wanted to debug any issues I ran into. 

After steps #1 and #2, your site should look something like this (the highlighted are the jQuery/ThickBox components) ...

image

And your page will include the following JavaScript and CSS references.

image

3.  Next, you need to update the thickbox-compressed.js and thickbox.js files to include the location of the loading graphic you would like to display while the ThickBox is loading.  The ThickBox component displays an animated gif while the ThickBox is being displayed.  By default the component assumes the location of this graphic is images/loadingAnimation.gif.  So if this isn't the location on your web server you will have to manually update the thickbox.js and thickbox-compressed,js files and update this variable.  In my app, I am storing the graphic at _assets/img/loading.gif so I updated the thickbox JavaScript files to use this path instead of the default one.

 

   1: //  change this ...
   2: var tb_pathToImage = "images/loadingAnimation.gif";
   3:  
   4: //  to this ...
   5: var tb_pathToImage = "_assets/img/loading.gif";

 

 

Programming Model

The ThickBox programming model works as follows ...

You add an A or INPUT to your page and adorn it with the thickbox CSS class.  Then, like magic, when the element is clicked the ThickBox is displayed.  Here is a real simple example that shows an image in a ThickBox - when the A is clicked the nested IMG element is displayed in a ThickBox.

   1: <a href="images/single.jpg" title="add a caption to title attribute / or leave blank" class="thickbox">
   2:     <img src="images/single_t.jpg" alt="Single Image"/>
   3: </a>

 

The ThickBox also supports other scenarios too - like displaying some in-line content from the page inside the ThickBox (like a hidden DIV or something) as well as showing an IFRAME in the ThickBox.  These other scenarios require some additional parameters - and the ThickBox uses some of the existing INPUT and A attributes to specify these values ...

  • title - you can use the A or INPUT's title attribute to specify a title for the ThickBox
  • A.href and INPUT.alt - the value of this attribute is parsed into some of the parameters that control how the ThickBox behaves

For example, here is how you would use the ThickBox to display some hidden content on your page...

  • The href attribute of the A element contains the encoded parameters
  • #TB_inline tells the ThickBox that the content to be displayed exists some where on the current page
  • height/width specify the height and width of the ThickBox
  • inlineId is the ID of the element that will be displayed
  • modal specifies that the ThickBox will be displayed modally
   1: <a href="#TB_inline?height=155&width=300&inlineId=hiddenModalContent&modal=true" class="thickbox">Show hidden modal content.</a>

 

And here is a very simple example of an anchor that when clicked displays some hidden content.

   1: <a href="#TB_inline?height=50&width=300&inlineId=hiddenModalContent" title="Simple Demo" class="thickbox">Show hidden content.</a>
   2: <div id="hiddenModalContent" style="display:none;">
   3:     <div style="text-align:center;">Hello ThickBox!</div>
   4: </div>

 

And here is what it looks like.  In this sample, the dialog isn't modal so it can be closed via the Close or pressing the Escape key or just by clicking any where else on the page.

image

 

ASP.NET AJAX Integration

And now of the real question - how well does the ThickBox work with my WebForms apps?  Well, I tried porting over my previous sample of using the ModalPopup to edit rows in a GridView.  Here is how it went ...

  • I started down the path of using the ThickBox to display some hidden inline content, but that didn't work out to well.  The ThickBox takes the contents of the inline content and moves the DOM elements out to an immediate child of the document's BODY element.  That doesn't work too well when used with WebForms because I need everything contained within the FORM element for my page to work properly. 

Check it out - below is what the DOM looks like.  See how the FORM element and the TB_window DIV are siblings - that isn't going to work. 

image

But this isn't exactly a show stopper either - I can still move my detail content over to a separate page and have the ThickBox load it up using an IFRAME.  So that's were I went next.

  • I updated the markup for my main GridView and changed the last column to render an A tag with all of the parameters I need to tell the ThickBox to load up a new page in an IFRAME.  Remembering how the ThickBox parses the arguments from the anchor's href and title attributes, I used a databinding expression to build out the values for these attributes. 

When the dialog shows I want to include the Customer name in the title, so I am using the ContactName property to build the title value.  I also want to show the Detail.aspx page passing the current rows ID value as an argument.  So I again use a databinding expression to set the href attribute to the value I want.

   1: <asp:GridView ID="gvCustomers" runat="server" DataSourceID="odsCustomerList" CssClass="datagrid" GridLines="None" AutoGenerateColumns="false">
   2:     <Columns>
   3:         <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="true" />
   4:         <asp:BoundField DataField="CompanyName" HeaderText="Company" ReadOnly="true" />
   5:         <asp:BoundField DataField="ContactName" HeaderText="Name" ReadOnly="true" />
   6:         <asp:BoundField DataField="ContactTitle" HeaderText="Title" ReadOnly="true" />                
   7:         <asp:BoundField DataField="Address" HeaderText="Address" ReadOnly="true" />                
   8:         <asp:BoundField DataField="City" HeaderText="City" ReadOnly="true" />                
   9:         <asp:TemplateField>
  10:             <ItemTemplate>
  11:                 <a id="btnShowPopup" runat="server" class="thickbox" 
  12:                     title='<%# Eval("ContactName", "Details for {0}") %>' 
  13:                     href='<%# Eval("ID", "Detail.aspx?ID={0}&TB_iframe=true&height=220&width=400") %>'>Edit</a>                
  14:             </ItemTemplate>
  15:         </asp:TemplateField>                        
  16:     </Columns>                    
  17: </asp:GridView>
  • Next, I created the Detail.aspx page that displays the detailed information for a given Customer.  This page requires a single parameter, ID, that passed via the querystring.  This page displays the Customer detail information in a DetailsView and allows you to edit the values.  The page has a single Save button that when clicked ensures the page is valid, saves the changes back to the data store, and closes the ThickBox window.

The interesting part here is that the Detail page is responsible for closing itself after the user presses the Save button.  So to accomplish this, I need to register a small script that will run after the Save has completed that will close the ThickBox.  To get this bit of work done, I first created a JavaScript function on the main page called updated that closes the ThickBox window using the ThickBox's tb_remove function.  Next, I need to let the main grid know that it needs to refresh itself (otherwise you wouldn't see any of the changes you just made).  I handle this by setting up a hidden Refresh button that when clicked causes the main grid to refresh itself.

Here is what the updated function looks like ... 

   1: function updated() {
   2:     //  close the popup
   3:     tb_remove();
   4:     
   5:     //  refresh the update panel so we can view the changes  
   6:     $('#<%= this.btnRefreshCustomers.ClientID %>').click();      
   7: }

 

And here is what the Detail page's Save event handler looks like ...

   1: protected void BtnSave_Click(object sender, EventArgs args)
   2: {
   3:     if (this.Page.IsValid)
   4:     {
   5:         //  move the data back to the data object
   6:         this.dvCustomerDetail.UpdateItem(false);
   7:         
   8:         //  register the script to close the popup
   9:         this.Page.ClientScript.RegisterStartupScript(typeof(detail_aspx), "closeThickBox", "self.parent.updated();", true);
  10:     }
  11: } 

 

  • And I actually need make one more modification.  My customer grid is contained within an UpdatePanel.  And even though this grid doesn't sorting or paging, the example as-is wouldn't work too well after the user triggered an event that causes the UpdatePanel to refresh itself.  The reason why is because the ThickBox works by fetching all of the A and INPUT's that contain the thickbox class - and this selection occurs just after the page is initially loaded.  And it doesn't happen again after that.  So we need to add a special piece of logic that will reapply the ThickBox to the A elements that are contained within our UpdatePanel.  And here is the bit of JavaScript that I am using to do this ...
   1: function pageLoad(sender, args) {
   2:     if(args.get_isPartialLoad()){
   3:         //  reapply the thick box stuff
   4:         tb_init('a.thickbox');
   5:     }
   6: }

 

This is again scanning the complete page for anchor elements with the thickbox class and adding the ThickBox behavior to them.  This bit of logic could be optimized because ...

  • We don't need to scan the complete page again, just inside any UpdatePanels that were refreshed.  This is where it might be useful to use a Sys.Component to auto-magically keep track of this stuff for us.  We could easily hook into some of the ASP.NET client side page events and reapply the ThickBox stuff to any elements that contained within an UpdatePanel.  This is pretty similar to the approach I used here to maintain scroll position across partial post-backs.    

 

Conclusion

So, after all of this, here are a few things I found interesting.

  • When I saw all of the scripts the ModalPopup required I couldn't help think it might be interesting if there was a way for the control to only render the scripts it needed to function based on the features you are currently using.  That would be useful.
  • It took me a while to learn the ThickBox's API.  Encoding the parameters into the href is crafty, but it also makes the features hard to discover without documentation.  The Toolkit has a very consistent API.
  • None of the jQuery stuff is going to have a server side API - so when using jQuery from my WebForms I am going to be injecting quite a bit more JavaScript from the page's codebehind than I am used to.
  • I didn't like how the ThickBox forces me to separate my detail widget into a separate page.  But the reality is that most of the jQuery stuff is not written with WebForms in mind.  So running into this stuff might be the norm when trying to use these scripts.

Also, keep in mind this is just one sample.  In my mind, this doesn't tell me to replace the Toolkit with jQuery or vice versa. 

 

That's it.  Enjoy!   

"

Monday, March 28, 2011

C# Programming Language (Covering C# 4.0), The (4th Edition)

C# Programming Language (Covering C# 4.0), The (4th Edition): "






The popular C# programming language combines the high productivity of rapid application development languages with the raw power of C and C++. Updated to cover the new features of C# 4.0, including dynamic binding, named and optional parameters, and covariant and contravariant generic types, this release takes the language to the next level by adding the ability to cleanly write programs that don’t rely on static type definitions. This allows dynamic programming languages such as Python, Ruby, and JavaScript to feel native to C#. The C# Programming Language, Fourth Edition, continues to be the authoritative and annotated technical reference for C# 4.0.




 


Written by Anders Hejlsberg, the language’s architect, and his colleagues, Mads Torgersen, Scott Wiltamuth, and Peter Golde, this volume has been completely updated for C# 4.0. The book provides the complete specification of the language, along with descriptions, reference materials, code samples, and annotations from twelve prominent C# gurus.


 


The many annotations bring a depth and breadth of understanding rarely found in any programming book. As the main text of the book introduces the concepts of the C# language, cogent annotations explain why they are important, how they are used, how they relate to other languages, and even how they evolved.


 


This book is the definitive, must-have reference for any developer who wants to understand C#. With annotations from: Brad Abrams, Joseph Albahari, Krzysztof Cwalina, Jesse Liberty, Eric Lippert, Christian Nagel, Vladimir Reshetnikov, Marek Safar, Chris Sells, Peter Sestoft, Jon Skeet, and Bill Wagner.


 


 




Download Here


If you liked this post, buy me a beer. (Suggested: $3 a beer or $7.5 for a pitcher)



"

Sunday, March 27, 2011

30 Developer and Designer Apps for iPhone, Android and BlackBerry

30 Developer and Designer Apps for iPhone, Android and BlackBerry: "Thumb_thumb

There has been a steady stream of mobile apps tailored to web developers and designers, transforming mobile devices into a virtual Swiss-Army Knife of tool applications.

I looked at the top one-hundred developer-oriented and designer-oriented apps with the highest user ratings and the most downloads for each of the top three mobile devices: Apple’s iPhone, Google’s Android phones and Research in Motion’s BlackBerry. I then handpicked from that group of one hundred to focus on twenty highly rated and popular developer and designer apps for each phone.

Download these apps and start developing and designing while on the go.

Developer Apps


Developer’s Tool Kit. A full-featured toolbox for any web developer or programmer featuring a comp...

"