remix uk day 2

Day 2:
Understanding the ASP.NET Model-View-Controller – Scott Guthrie
The ASP.NET MVC project
is a strange one for me. A few months back I read up on it and thought
it looked really good but I’ve not actually had the time to try it out.
Scott’s presentation was excellent. What I especially liked was the way
he showed the warty way of doing something and then showed the simpler
method. This is excellent because the warty way makes it obvious what
the code is actually doing, whereas too many people only show the nice
clean method which makes it far harder to understand what is happening
under the covers. Some of the features I haven’t seen before were just
excellent, the validation messages were really well handled. I’m very
impressed by MVC, I don’t have a lot of love for the ASP.NET psudeo
event model/page life-cycle. Well worth attending the dev-based
presentation. 10/10.

Computing power, screens, and networks: Impact on authored content – Tim Regan
Tim
was, by his own admission, a little nervous presenting but he shouldn’t
be. I would group the mobile part of the presentation in the, ‘ways to
visualize data’ presentations with a specific focus on analysing
literature. I found it very interesting but since I don’t have a need
to analyse patterns in literature the specifics are of much to use to
me directly. But again it re-enforced my interest in thinking about
different ways to present data. Good presentation but some difficult
for me to use in my every-day role – 7/10

Beauty & the Geek – The Perfect blend of left & right brain – Conchango
Following
in the MS Expression wave of designers & developers working
together Conchango shared their experiences. I’ve worked in this area a
bit and it was interesting to hear how they were getting around some of
the problems, e.g. no version control for the designer. I thought it
was interesting to make someone the owner of the xaml. I was a little
surprised to hear that the developer spent so much time in Blend. I
think that the separation of Blend and Visual Studio is a great way to
ring-fence the responsibility. I agree that Visual Studio does need
better basic handling of xaml in the design, at least to be able to
navigate around the visual tree and highlight the xaml, but apart from
that leave Blend well alone unless you really are a designer! It was
also interesting to hear the pair-programming style of working (even
more reason for the dev to leave Blend alone) as in my experience there
is usually a fair amount of delay between the developer and the
designer re-synchronizing their efforts. Interesting presentation and
it’s nice to hear the experience of others. I think the developer vs.
designer jokes are a little weak these days but I can forgive
that…oooh get me 😉 8/10

Behind Every Great Site There is Great Data – Eric Nelson
I’ve
had the good fortune to attend a number of Microsoft seminars hosted by
Eric over the years, yes I do remember him joining (good grief).
Although obviously Eric works for Microsoft but I’ve always thought his
presentations are from the point of view of their customers, i.e.
telling us as it is rather than as it should be. To be honest I nearly
didn’t attend this as I’ve had some exposure to these technologies and
had written some of them as too imature, but I thought it would be good
to hear Eric’s impression. In this presentation Eric did a good job on
untangling the differences between Linq to SQL and Linq to Entities (he
has a great diagram for this on his blog) and although I still remain sceptical about the EDM I certainly feel more comfortable understand
how keep the path to it open. I would have liked a few min’s about
where this fits into a n-tier design, e..g where to put the business
rules but overall I’m glad I attended. 9/10

Mobile User Experience – Inspiring new ways of design & development – Antony Ribot
Antony
talked about the issues of providing a quality and clear interface for
the various mobile devices out there. I felt the content was fine but,
for me, the presentation wasn’t as slick. This resulting in a slightly
muddled message, however Antony is clearly a smart person, perhaps a
bit of nerves. 6/10

Sneak Peak and end – Paul Foster
A few little demos and adverts and a Balmer-like burst from Paul 😉 He did re-enforce the importance of letting people have the time to be creative, something I yearn for in my current post.

For Day 1…

remix uk Day 1

I’ve just got back from reMix UK (Mix UK) in sunny (and it was) Brighton. As is my way I thought I’d provide a little mini-review of the event…

Day 1
Keynote: Bill Buxton & Scott Guthrie (and others)
Great start from Bill who gave a passionate talk about the importance of design and user experience, including his personal mantra of, Ultimately, we are deluding ourselves if we think that the products that we design
are the "things" that we sell, rather than the individual, social and cultural experience that they engender,
and the value and impact that they have. Design that ignores this is not worthy of the name.
He backed that up with a great advert from a mountain bike company showing a rider have an exciting ride through a stream but you cannot see the make (or model) of the bike he’s on.

Bill talked about Jonathan Ive the designer behind Apple’s IMac & Ipod. He explained that he was at Apple during the bad years and it was only when Steve Jobs took over was he given the chance. The important points I took from that are (well it was obvious)  a) the company needs to put design at equal importance as any other part of developing & releasing a product b) you need to free employees’ from the n+1 release treadmill and allow them to fulfil their potential. I really enjoyed Bill presentation.

Scott’s presentation didn’t excite me quite as much, to be fair there wasn’t a lot of stuff that was new to me. He introduced folks from ITV and (InnerAthlete???). Again the ITV presentation was all about streaming…again. Ok I can see that it’s important to application developers because it helps to increase the Silverlight user-base but for me streaming video is not where the value of Silverlight is. So it was good to see the application side represented by the Athletic training software. Although the application design wasn’t my cup of tea.

Overall I would have preferred to leave after the first part of the keynote, but I’m sure for members of the audience who haven’t been exposed to Silverlight before then it would have been a great keynote. 7/10

It’s not necessary to be understood – Brendan Dawes
As a developer these are exactly the sort of sessions that I attend Mix for. Brendan showed lots of interesting ways to visualize data, although I doubt I could actually use any of them directly it helps me approach showing data in a different way. It also encouraged me to play more with development rather than only create things with a specific business purpose. 9/10

Designing for the Wild: Sketching Experiences – Bill Buxton
More of the same from Bill, with some interesting views about how much detail you put into your early designs and how many proposed solutions you deliver early on. It certainly struck a cord with all too many prototypes making it into a product because they were the only choice rather than necessarily being the best solution. I did feel that Bill didn’t offer advice for smaller companies working on much tighter budgets where even if you provide the roughest sketches to a client you’ll have burnt too much money and time. For that reason it’s not a perfect score. 9/10.

ADO.NET Data Services for the Web – Mike Flasko
Although I tend to avoid the development track I felt I needed to hear a good presentation on ADO.NET Data Services because I felt very suspicious about the use of this. Mike did a good job of explaining it even though it was very similar to previous presentations. I feel I have a much better appreciation of how and when to use it. I still would like more to be said about the relationship with WCF, i.e. I want to switch to a faster protocol than http, how would I do that?  8/10.

Becoming human; smiling like you mean it, & learning to say hello – Denise Wilton
A nice presentation from the Denise Wilton (Graphic Designer & Creative Director of moo) talking about fostering a friendly atmosphere for a site. By actively participating in a "community" the whole experience from the user to the staff fielding calls is improved. I lot of the talk was around community and public sites and was very interesting, perhaps a bit too long a session for the content but Denise is a very good presenter – I liked the humour and the accidental use of some…stronger language as it was heart felt rather than scripted. 8/10
[Edit] Forgot to mention the "canyon of despair" (smells too much like marketing speak for me 😉 ) which was a nice way of depicting the difference between a hold-you-hand easy application and an advanced bells-and-whistles application or rather that bit in-between the two where a lot of application want to live.

Day 2…

Remote Desktop Console feature after Vista SP1

Remote Desktop allows the user to connect to the remote machines Console session. This is very useful is side-stepping some issues with Visual Studio (perhaps they’ve fixed those now?). However, after installing Vista SP1 I noticed that even though I was specifying the /Console flag I was getting a standard session. Apparently this has changed and you must now supply /admin instead.

Using Classic ASP to avoid performance problems with ASP.NET Dynamic controls

First off I must admit that I’m not the biggest fan of ASP.NET and you’ll often find me accusing it of attempting to shoe-horn an old VB6 style event model to the web. However, I do concede that it is a very good attempt at doing just that and helping to take away much of the plumbing work that was required to write a decent classic ASP application, one of these issues was ‘solved’ by Viewstate. Love it or hate it viewstate is an easy way to maintain the values of the HTML form elements between post-backs. So everything is Ok then? Well I’m conveniently ignoring the size issues to talk about a common pattern of using a single page and changing the view of the page by using dynamically created controls. Typically the single page has no content of its own but some stimulus, such as the query string, allows the code-behind to create completely different views of data. I’ll stop short of saying it’s a way to implement MVC/MVP patterns but you could do it.

An Example

So as an example consider creating an application that allows the user to search for employee details, by selecting from a set of criteria. Once selected the user presses the "show me the results" button and the page takes the criteria and displays details. The user can then change the details and update them or move back to the criteria page. So introduces our first problem, what details to display for the employees?

Displaying details that are only known at run-time

Ok so it is a bit contrived, but let’s say that the number of text boxes change due to the type of employee. The code runs a fairly expensive SQL query, that takes 30 seconds to complete, in order to discover the employee details to display. But we need to be careful where to run this query in order to correctly construct the controls for ASP.NET to use. The basic part of the page life-cycle to create dynamic controls is in the OnInit override. Here are some snippets, I know there is code in there I’ve not explained, hopefully later you’ll see how I’ve populated those…

protected override void OnInit(EventArgs e)

        { 


            base.OnInit(e);


            // Add dynamic controls here


            CreateView(); 


        }


private void CreateView()
        {
            if (this.lastView == this.currentView)
            {
                // do nothing, rely on the view state populating the fields
                return;
            }
            // not the same view, so trash whatever went before
           
// (probably nothing yet but just to be safe)
            this.PlaceHolderDynamicContent.Controls.Clear();

            if (this.currentView == 1)
            {
                CreateView1Controls();
            }
            if (this.currentView == 2)
            {
                                      // Warning, expensive discovery query in here
                CreateView2Controls();
            } 
        }

Ok so we’ve created the dynamic controls, but how do you read the changes the end-user has entered?

Reading changes made to dynamic controls

Leaving the well trodden road of static controls can be tricky, to read data from dynamically created controls in a post-back you must do so after ASP.NET has; a) Create the control hierarchy used to create the previously rendered page b) inserted the values into the controls from the viewstate and post data. The basic place to read the data is the page_load event.

protected void Page_Load(object sender, EventArgs e)
        {
                // Read saved data from dynamic controls here
                SaveLastView();
        }

So we can create a view that was unknown at design time and read the data from those dynamic controls so what’s the problem?

Running expensive discovery queries on post-back

As we’ve seen in order to read the data from dynamic controls we have to help ASP.NET out by creating the initial set of controls during post-back. However, to do that we’ll have to re-run that expensive discovery query again. If the user has changed some details then it’s an expense we’ll have to put up with (or use some other caching mechanism). However, what if the user hasn’t made any changes and want to return to the Criteria view? Currently we’d blindly run the discovery query and incur 30 sec hit only to throw away all the controls and create the control set for the criteria…seems a bit of waste. So how can we know that the user has navigated away from view when we can only read the data in the Page_Load, but that happens after the Page Initialize and therefore after we’ve run the discovery query! Well this is where classic ASP can come to the rescue.

Classic ASP rides to the rescue

The ASP.NET page life-cycle isn’t magic, the browser posts data to the server, ASP.NET process the data and transforms it into the event based model. There is lot of smoke and mirrors going on but the underlying process hasn’t changed from classic ASP, the Response object still contains the user’s posted data. So if we have a navigation control called MyButtonView1 then you can fish directly into the Response object and get the value via Response.Form["MyButtonView1"]. This means that in the Initialize event we can know if the user is navigating away and therefore we don’t have to run the discovery query for the details. Hurray all the problems solved? No, what happens if the user has made some changes and then navigated away? I knew you’d ask that. Well this is where it becomes irritating, because you have to write more an more code to support the dynamic controls reaching a point where you may as well write classic ASP from the off. Oh well, here is one way to do this. Add client side OnChange to the dynamic controls that update a single "HiddenFieldNeedsToSave" control, then in the Init you can check this too. So finally we’ve got a mechanism to support dynamic controls without having to needless re-run expensive discovery queries.

protected override void OnInit(EventArgs e)
        {
            this.lastView = Convert.ToInt32(Request["HiddenFieldView"]);
            if (Request["ButtonView1"] == "View1")
            {
                this.currentView = 1;
            }

            if (Request["ButtonView2"] == "View2")
            {
                this.currentView = 2;
            }

            if (Request["ButtonSave"] == "Save")
            {
                this.isSaving = true;
                this.currentView = this.lastView;
            }
            base.OnInit(e);

            // Add dynamic controls here
            if (this.isSaving)
            {
                CreateLastView();
            }
            else
            {
                CreateView();
            }
        }


 protected void Page_Load(object sender, EventArgs e)
        {
            if (this.isSaving)
            {
                // Read saved data from dynamic controls here
                SaveLastView();
                this.isSaving = false;
                CreateView();
            }
            this.HiddenFieldView.Value = Convert.ToString(this.currentView);
        }

Hopefully I’ve missed something and some nice person can show me the error of my ways, but until then my way of solving this ASP.NET problem is to turn to classic ASP…or just switch to using the MVC project 😉
   

Where to add dynamic controls in the asp.net page life cycle?

There are some things in software development that I just keep having to re-read. One such subject that refuses to stay in mind is where in the asp.net page life-cycle should I; a) add dynamic controls b) set the properties of those controls c) read user saved values from those controls. So as an aid-mémoire:

OnInit – Create the dynamic controls. This is the basic place to create controls, without getting into the whole re-loading of the cycle when adding child controls.
Page_Load – read user saved values and set control values. This is used ’cause proving the dynamic controls have already been created (see above) then the viewstate and post-back mechanisms will have loaded the correct user set values.

There, why is that so hard to remember?

How multiple web sites can share one binary folder

I answered a post about how you can share a single binary folder with many web sites. I can certainly see the advantage of having configurable sites (different web configs) but share the same binary folder to make it easier for maintenance. My first thought was that you could use virtual folders but unfortunately the code probing won’t see the virtual folder…shame. So I looked into the ye olde unix (or nix) style of symbolic links, thing create shortcut link on steriods.  My first idea was to create a ‘hardlink’ of the bin folder itself. E.g.

ActualBinaries\Bin

Web1\Bin (really hardlink to ActualBinaries\Bin)

Web2\Bin (really hardlink to ActualBinaries\Bin)

Although the CLR did indeed go to the correct folder it failed to load the assemblies in there complaining that the format of the path was wrong. So sensing that I was close to something I tried creating an real bin folder and hardlink the indicidual files. E.g.

ActualBinaries\bin\MyComponent.dll

Web1\bin\MyComponent.dll (really hardlink to ActualBinaries\bin\MyComponent.dll)

Web2\bin\MyComponent.dll (really hardlink to ActualBinaries\bin\MyComponent.dll)

Now that worked! So how do create one of these links? Well it’s actually quite straightforward;
fsutil hardlink create
"C:\Web2\bin\MyComponent.dll"
"C:\ActualBinaries\bin\MyComponent.dll"

Apparently Powershell can easily create them too, although I’ve yet to try that. So is it worth the effort? I can see that running one MSI would be handy, especially when you’ve got COM registrations going on. However if you’ve only got .net components and no extra registrations then I doubt it’s worth the extra effort.

Virus checkers, the good and bad

I’ve previously written that I have grave doubts about Virus checkers. Well this weekend my g/f laptop (XP SP2) found itself under attack from the malware known as ‘XP Antivirus 2008’ – yes it’s a genuine virus/malware masquerading as a anti-virus tool. Fortunatley Norton Anti-virus spotted it pretty quickly and did just enough to stop it causing too much damage. Although it didn’t get rid of it completely it stopped it ‘working’ and with the additional help of Malwarebyte the system was soon cleaned. So 1:0 to the Virus checkers. However, the previous week my version of Vista running on the Mac via Parallels started to act very oddly. Visual Studio wouldn’t compile properly, Task Manager wouldn’t go away, Windows Update wouldn’t…update. I quickly narrowed it down to AVG anti-virus not correctly updating. Every time I stopped it attempting to update everything else worked fine. So I tried to uninstall it, the uninstalled just stopped after about an 1 hour of doing very little. I rebooted in safe-mode and uninstalled it in an instant. Good ridance. Finally I can get back to using Vista…1:1.

Fun with IIS http compression

Ah the wonderful world of System Administration. My first task of the day was test a site using HTTP compression. So I followed the instructions to turn on http compression in IIS6. What a wonderful mix of UI, XML file fiddling and vbs scripts that was…<good grief>. Finally I managed to start seeing the production of compressed files in IIS’ folder. "Hurray, it’s working", I foolishly thought. My specific test site just kept failing, nothing would render a page. So, like all "good" developers I set compression to global, i.e. all the sites and went to the default iisstart.htm to see if that was ok. Sure enough the compressed version of it appeared in the IIS folders and IE7 rendered it without any fuss. "Hurray, it’s working"…I foolishly thought. Firefox 3 just stubbonly says, ‘The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression’. However, it looks like that happening on a number of sites with FF3. So I tried Safari. What a joke, doesn’t seem to want to see the page at all, moaning about a domain error. Opera 9.5, to the rescue, it acutally rendered both my test page and the iisstart.htm. Well I say rendered, it just showed me the contents of compressed file, i.e. it hasn’t bothered to uncompress it! Chocolate fire-guard anyone? So time to admit defeat and go off to the TechNet forum. Oh it just keeps giving. I tried to login, complained that my account hasn’t been verifyed, even though I used it about 1 year ago now. So I thought I’d register again. Every character I typed threw up a javascript error with IE asking if I wanted to debug it. What a waste of time.
 
So all in all my first professional brush with IIS6 compression has been…less than satisfactory.
 
[Edit]
I’ve since tried download ZipEnable from Port80 which didn’t help, but then I copied the settings from http://www.codinghorror.com/blog/archives/000059.html and finally it started to work, all the browsers too.
 
 
 
 

More Microsoft AJAX views

I do have a tendancy to get annoyed when I think about Microsoft’s web offerings of ASP.NET and more recently their AJAX libraries. I’ve had a little rant about it before but I thought Adam Kahtava has written a good post on the AJAX side of things here, The ASP.NET AJAX Framework is for DUMMIES!
 
I’m not sure I’d go so far as to say the library itself is bad, IMO it has a lot in common with Prototype, but I certainly feel the pain of pandering after the server controls. Although there are a number of "pure" AJAX libraries to choose from some also have projects/extensions to help with server controls, e.g. http://www.codeplex.com/YuiDotNet, so maybe you can move to another library without leaving the server controls behind.
 
 

Fun with Microsoft AJAX UpdatePanel

Recently I’ve been asked to look into a problem where code running in an UpdatePanel was generating the following error;

sys.webforms.pagerequestmanagerparsererrorexception: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.write(), response filters, httpmodules, or server trace is enabled.
Details : Error parsing near ‘<!DOCTYPE html PUBLI’.

So what’s happening here? The UpdatePanel mechanism works by requesting the whole aspx page from the server and then using black-boxed JavaScript code to grab the changes that the UpdatePanel area represents in order to update the browser accordingly. This requires that the UpdatePanel’s client side script gets exactly the page it was expecting. Any changes, such as using document.write or traces will upset this requirement and you get this error. Another way of upsetting this apple cart is if the server decides to totally change the page, i.e. the server issues a Server.Transfer. Server transfer is a very seductive technique because it doesn’t require bouncing any requests off the client, the server simply changes (transfers) from rendering page A to rendering page B. However, when we look back at the UpdatePanels requirements for having the same page then it quickly becomes obvious that it’s going to get upset again! So that’s it, I now know how to avoid upsetting the UpdatePanel, well so you’d think. In the particular case I was asked to look at the server was issuing a page redirect. At first thought you’d think, "aha, it must be the page the UpdatePanel expects", but no. The UpdatePanel is savvy enough to realise that a 303 redirect isn’t really meant for it, so it passes it to it’s container, i.e. normally the browser window. So although you can’t use the "page moved" technique to change the service end-point at least the server code can issue redirects without having to know if the client is a browser or an UpdatePanel. So why am I seeing the error still? Hmm, I’m still not sure. Something somewhere is consuming the 303 redirect and then correctly requesting the page B from the Server. Page B is then consumed by the UpdatePanel, therefore behaving like a Server.Transfer and hence I see the error. Unfortunately the page structure is complex, with a number of dynamically created controls and iframes so something in that goo is consuming the 303 before the UpdatePanel. So what’s a developer to do? Well handle the error that’s what 😉 Rather than write lots of nasty code to dynamically rewrite the UpdatePanel’s JavaScript you can use the following, Sys.WebForms.PageRequestManager endRequest Event

In my case I chose to examine the error condition, if there’s one the change the window.location and redirect the client to an error page. You can examine the args to see exactly what was returned to make more interesting decisions about how to process the error. Also you should mark the error has handled (=true) if you don’t want the UpdatePanel to carry on raising browser errors.