Overriding Modernizr

Modernizr is a great tool for browser feature detection, but there are times when it’s useful to override Modernizr’s detection and force the configuration of features that are available, both on the Javascript object and also the CSS marker classes. An example of this is when using Chrome Dev Tools to write fallback functionality for older mobile devices – Windows Mobile 7.5 and a Galaxy Ace with Android 2.3 have been problems for me lately.

To help with this I wrote a simple modernizr-override helper to take a predefined Modernizr configuration and inject it on top of the detected features in Chrome.

To get it, and see how to use it, head over to the Github repo here.

SignalR: The ConnectionId is in the incorrect format – an alternative cause.

Recently, on an application using SignalR, we found that we were getting many System.InvalidOperationException: The ConnectionId is in the incorrect format exceptions (sometimes 10 per second) from the SignalR hubs in the site.

While there is plenty of discussion on the causes of this error in SignalR documentation and on Q&A sites, they mostly discuss problems with changing levels of authentication (SignalR defines a new connection when the auth level, or authorized user, changes). In this case though this wasn’t relevant. The volume implied that this was unlikely to be the cause, and in anycase, the site was already written to cope with these changes on login.

The cause turned out to be search engine crawler services. Continue reading SignalR: The ConnectionId is in the incorrect format – an alternative cause.

ASP.Net Webforms – Dynamic UpdatePanels and UserControls issue

Have come across an interesting issues in ASP.Net WebForms when migrating a project from 3.5 up to 4.5.

The site in question is extremely dynamic, the page is built up based on configuration in a CMS fashion.

However in 4.5 we have a problem – when more content is added into the page via a button click, not all the markup for the content appears.

Continue reading ASP.Net Webforms – Dynamic UpdatePanels and UserControls issue

DropDownList Helper For Enums

Its useful to be able to have a helper that converts a Enum typed property from an MVC Model directly into a drop down list without any messing about creating lists of possible values etc.

I found this answer on StackOverflow which has example code for just such a helper: EnumDropDownListFor. However, like a few who have tried it I found some issues around getting it to work to pre-select the value held in the Model’s property.

Continue reading DropDownList Helper For Enums

EditorFor and Interfaces Pt2 – Binding

This is a two part piece on working with Interfaces in MVC via the Html.EditorFor helper.

In the first part – “Display” just covers one of those things I tried on the off chance, and was rather surprised that it worked right out of the box.

In this second part I’ll have a look at the next step of the process – binding these interfaces back to their models.

For reference, I’m working with MVC4, in VS 2012 For Web. I think this will also work in MVC3 at least.

Background

When model data is posted back from the client, an instance of the model class is automatically created for it and passed to the handling action. The process of converting the data into a model instance is called binding, and, normally, this is handled for us automatically.

If, as in Part 1, we’re using an interface as a model, and then allowing EditorFor to automatically render the correct controls this processes stops working, as the automatic binding isn’t able to resolve our interface into a concrete class to instantiate and fill.

Instead we have to implement a custom binding. In the case of interfaces we can make this fairly simple with Generic BaseInterfaceBinder that will work for all interfaces we might want to work with.

Continue reading EditorFor and Interfaces Pt2 – Binding

EditorFor and Interfaces Pt1 – Display

This is a two part piece on working with Interfaces in MVC via the Html.EditorFor helper.

The first part – “Display” just covers one of those things I tried on the off chance, and was rather surprised that it worked right out of the box.

In the second part I’ll have a look at the next step of the process – binding these interfaces back to their models.

For reference, I’m working with MVC4, in VS 2012 For Web. I think this will also work in MVC3 at least.

Background

For a slightly messy user interface I’m working on, I wanted to be able to have a Model that holds a list of classes that implement an interface.

There is a possibility that all the classes might not be the same, and I was concerned that I was going to end up with a messy switch statement in my View that called the right Partial depending on which class I found in the list, and that this switch might need to be maintained on an on-going basis.

Continue reading EditorFor and Interfaces Pt1 – Display

DevExpress ASPxTreeList – Single node selection via client side JavaScript.

Using the DevExpress ASPxTreeList control recently I came across the problem of how to only allow one node checkbox to be selected at once.

There are examples on the DevExpress support site of implementing this using server side code and postbacks, however this isn’t so desirable, as incurring a postback for every time a node is clicked is fairly expensive.

I had a look into how to implement this using the ASPxClientTreeList functionality available to deselect nodes when other nodes are selected. The solution I worked out works reasonably well, with one caveat which is covered at the end.

Continue reading DevExpress ASPxTreeList – Single node selection via client side JavaScript.