Archive for the ‘Misc’ Category

Gotcha – Update Panel causing full post back

Tuesday, June 29th, 2010

Problem

The age old story of porting a Visual Studio 2003, C# Asp.Net project to Visual Studio 2008 (so .net 1.1 to 3.5) led to a failure when a new AJAX enabled page was being developed.

The page was very simple and boiled down to this:

<body>

    <form id="form1" runat="server">

    <asp:ScriptManager runat="server" />

    <div>

        <asp:UpdatePanel runat="server">

            <ContentTemplate>

                <asp:DropDownList ID="list" runat="server" OnSelectedIndexChanged="SelectedIndexChanged" AutoPostBack="true">

                    <asp:ListItem Text="1" />

                    <asp:ListItem Text="2" />

                    <asp:ListItem Text="3" />

                </asp:DropDownList>

            </ContentTemplate>

        </asp:UpdatePanel>    

 

        <asp:UpdatePanel runat="server">

            <ContentTemplate>

                <asp:Label runat="server" ID="lbl" Text="initial" />

            </ContentTemplate>

        </asp:UpdatePanel>

    </div>

    </form>

</body>

With the code behind just updating one control with the value of another:

public partial class Default : System.Web.UI.Page

{

    protected void SelectedIndexChanged(object sender, EventArgs e)

    {

        lbl.Text = list.SelectedValue;

    }

}

Unfortunately the whole page ended up being refreshed and not just the value of the control being updated (a label in the example above).

Reason

After half a day of tracking the problem down, we tracked it to the web.config and found the following entry:

<xhtmlConformance mode="Legacy"/>

 

Take this entry away and the Ajax world works.  It’ll be just my look that the rest of the site doesn’t!

Charity Drag Race

Friday, May 14th, 2010

Yeah, I get to dress up as a woman for the second year running and all in a good cause!

This has nothing to do with technology and all to do with attempting to get some money together for a local hospice.

Why You Should Care

Ashgate Hospice is an independent registered charity (number 700636) that provides specialist palliative care (care to relieve pain rather than cure) and support, both at the Hospice and within the community, for adults and their families across North Derbyshire. Everything we do at Ashgate Hospice gives patients and their families all the help and care they need to continue living for every day.

It costs Ashgate Hospice £4 million a year to provide these valuable services, of which £2.3 million needs to be raised purely through voluntary contributions and fundraising.

The fancy drag race is being held in order to raise funds for the Hospice and is also being held to give men both young and old, the opportunity to run round in a dress before having a beer.  Win-win situation.

Last Year

A few of us took part last year on this 5 mile road race around Chesterfield and it was all good fun.

DSC00104 Image100

Even the kids wanted a go.

Image101

Give, give, give!

ASP.NET Ajax client-side framework failed to load.

Sunday, May 2nd, 2010

ASP.Net on .Net Framework 3.5 and a simple bit of AJAX using ScriptManager and a single UpdatePanel that contained a few divs.

The Partial Rendering just didn’t work and in debug I got this error:

ajaxError

Turns out that it was simple.  The script manager was by default trying to find the JavaScript functions in some files that I was not shipping, rather than in some built assemblies that I did.

I cleared the ScriptPath property on the ScriptManager and AJAX sprung into life!

ScriptManager

HTTP Error 500.19 - Internal Server Error + IIS 7.5

Tuesday, April 20th, 2010

This is the error that faced me the first time I deployed a .net Framework 3.5 web site to IIS via Visual Studio 2010 and then tried to run it.  After a couple of hours of digging I traced it back to the application pool but I thought it worthy of a write-up.

Problem

Attempting to run a .net framework 3.5 web site hosted in IIS 7.5 (deployed via Visual Studio 2010) gives the following error information:

error

config

Error message:

There is a duplicate ’system.web.extensions/scripting/scriptResourceHandler’ section defined

The error points to sections in the web.config file that ships with the site, a clearer view of which is here:

   1: <configSections>

   2:   <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

   3:     <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

   4:       <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

   5:       <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">

   6:         <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>

   7:         <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

   8:         <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

   9:         <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

  10:       </sectionGroup>

  11:     </sectionGroup>

  12:   </sectionGroup>

  13: </configSections>

This is strange because:

  1. The site runs fine in Visual Studio 2010.
  2. It works when deployed into IIS via Visual Studio 2008 (on a different development machine and in live).
  3. This site works if you alter the framework target to be .net 4.0 and then deploy to IIS and run as normal.

History

This web site was originally developed in Visual Studio 2008 but desperate to try 2010, I followed the procedure below:

  1. Installed 2010 on a clean machine (nothing in IIS).
  2. Converted the 2008 solution but kept the framework target as 3.5.
  3. Ran from Visual Studio.
  4. Deployed to IIS and attempted to run from there.

Fault Finding

My first thoughts were:

  1. That IIS thinks this is a .net Framework 4 site rather than a 3.5.  I find this hard to check as aspnet_regiis –lk does not work on Windows 7 (my development OS) and finding anything in IIS 7 is a pain in the neck.
  2. Visual Studio 2010 has messed something up.

Confirming the versions of the target assemblies for the site was problematic however.  When the site was built as .net 4 and so worked, I was able to view the Handler Mappings for the site.  When it was built for .net 3.5 and so broke, I couldn’t view the mappings as IIS displayed the same error as at run-time:

handlerMappings

Solution

It turned out that IIS was confused about the .net framework to use after all, or at least about the application pool version to use.

Viewing the application pools in IIS showed that I had the following:

applicationPools

As you can see, my application was sitting with the default web site inside the DefaultAppPool, which is configured to target .net 4.  Moving the site into the Classic.NET AppPool fixed the issue and worked a treat.

It would have been nice for this to have worked out of the box but you live and learn.

Staying up to date - What CPD?

Sunday, February 15th, 2009

Even before PDC 2008 I was starting to feel out of the loop. After developing in C++ for seven years I moved over to C# and needed to get to grips with not just the language but the whole framework.  Four years later and this still had not happened.  There was always something that I didn’t know, yet the work I was doing meant that as always, I only ever touched a fraction of what was available.

At the start of 2008 I was working in Spain and decided to cut my loses and learn the new stuff.  This meant that I could start to look forward to investigating all the new things that had shipped with .Net 3.0 (WCF, WPF, WF); even then I had a lot to get my head round.

However fate played its part and we moved back to the UK in March 2008, which promptly put a stop to my plans of keeping up to date.  I joined a company specialising in applications for Windows Mobile and whilst the new server-side code was C#, I was left on the legacy C++ stuff, concentrating on finding and fixing memory leaks, introducing smart pointers and thread synchronisation and generally trying to get the build and release process sorted out.

So now here we are in early 2009 and I’m finding the task of staying up to date technically, insurmountable. The only way to do this is to make a list and the list will have to be in a general priority order, which will probably change.  I can’t tackle everything at once though (or everything ever) but I have two projects that I’ll need to start soon, so they’ll be my motivators.  They should help to show what is important and thus drive what gets looked at first.

Project 1 - Windows Mobile

This project is a new version of our mobile product.  It takes work from a customer’s system and displays it to a user on a mobile device.  This will be written in C# using both the full and the compact frameworks and have to:

  • Take data from a user’s system.  At a minimum this means some XML conversion to convert the customer’s data into our format and back again.
  • Get the new data onto the client and update the user’s system with a response.  This sounds simple with the Synchronisation  Framework.
  • We don’t want to host the data ourselves.  This sounds like Azure.
  • The work that the client has to do is configurable and is basically a list of steps with input and output.  This sounds like Work Flow (WF).
  • The whole lot has to communicate.  Enter Windows Communication Foundation (WCF).
  • We’ve got to interact with a non-expert user on the mobile device.  Could be Silverlight but currently that requires permanent internet access on a mobile device, so we might have to stick with WinForms (which I know).  What about Windows Presentation Foundation (WPF)?
  • The mobile client will still need some form of business model but will be driven from the database.  This brings the Entity Framework into play.  It’s had some bad press but I still need to look at it.

Project 2 - Administration Dashboard

This is a long overdue system and whilst we want it to to work with our current product, we’d like to host it in Azure and swap out the back end in time to work with the new version of the product.  So, we are looking at:

  • The front end.  This IS going to be Silverlight.  Management like the pointy-clickyness of it and whilst I’d like to keep ASP.net as a back-up, “we’ve” (not me) have sorted out all the potential problems with Silverlight that we could see.  Ok, versions of a new technology like this are never new for long but I’d best get up to speed with SilverLight v2 whilst I can.
  • Hosted in Azure.  So Azure again.
  • Comms will be needed.  WCF again.
  • Abstraction from the data store.  Entity framework again (I think).

OK, where to start?  I’ve already programmed in C# for 4 years before returning to C++ so this should be the easy bit.  Let’s start there:

C# 3.0

  • New C# features (vars, extension objects, LINQ etc).
  • Using extension objects with XSLT looks like it’ll give a potential solution to the XML conversion.

C# 4.0 CTP

  • Dynamic types and whatever else there is.

Azure Services Platform

I’ve already been on what I believe to be the first workshop of its kind in Azure, so it makes sense to follow this up:

  • Write up the workshop.
  • Complete the labs.
  • Understand how to get a URL to point to the cloud.
  • Use Azure to host some HTML.
  • Use Azure to host some Silverlight.  I’ve already got as far as producing a bouncing ball in Silverlight so I’ll use this.

Silverlight

Silverlight on its own is no good for me.  It needs to get data dynamically.  I’ve already done a lot of the demos on design and standard “Flash” activities, so now it is time to look at Line Of Business needs:

  • Silverlight labs on Comms.
  • A little Silverlight app.
  • A WCF service.  Cool, WCF has been covered a little now too.

Entity Framework

  • Labs at this stage should be enough to decide if I need any more of it.

Sychronisation Framework.

I’ll need to understand this a lot and especially from the Windows Mobile world.

  • Labs
  • Implement my own synchronisation end points and understand when to do this together with what the implications are.
  • Check support in the compact framework.

Work Flow

I’ve got to get past the labs this time.

  • Labs
  • Small test application showing our standard entities.
  • Control the designer to allow novice users to implement their own flow (within my defined limits) to drive the test application in different ways.

WPF

Is there any need to cover this now that I have done some Silverlight?  Probably not until I need to.

That’s it!  By targeting what I learn along the lines of what I need the technologies for, I have a fighting chance of keeping my skills up to date whilst taking advantage of the latest technology to put together functional applications that our customers will actually want to use.

Still a whole lot of work though.  Help!