Entity Framework quick start

Microsoft’s Entity Framework has been around a while, but with it’s latest incarnation it is really shaping up nicely. I’ve been enjoying the ‘code first’ approach in version 4.1 of the framework. This allows you start your application design from POCOs, allowing the framework to infer the database design for you. For example, take the following Member entity model:

	class Member
		public int Id { get; set; }
		public string FirstName { get; set; }
		public string LastName { get; set; }

Continue reading


W3C validation of ASP.Net output

A while ago I had to make certain that a CMS driven site built in .Net met some validation criteria.  Specifically the XHTML markup.  Running it by the W3C validator service, the markup always failed.

I fixed the obvious within the web.config.  For example, the following is needed to force the application to render XHTML:

	<system .web>
		<xhtmlconformance mode="Strict"></xhtmlconformance>

If I painfully cut and pasted the HTML into the Validator’s form field, it passed.  The problem is, is that the service is not recognised by the Web server, and so a helper file in the application is required.
Continue reading


Validation groups in .Net

Evening all. Not posted in a while as I’ve plenty going on in the ‘real’ world. Anyway, last week I was building a search form whereby you could either search by reference code, or by using full search criteria.

The problem I had is that both search ‘forms’ existed on one Web Form, and I was using Validation controls to check each. So when using either submit button, both search groups were validated together. Not useful when I wanted to submit each set of controls independently of each other. So there I was, coding to disable either set of validation controls when a submit button is clicked.

“Validation groups!” I hear you cry. Yes, I know that now.
Continue reading

.Net, JavaScript

Using jQuery selectors to reference .Net controls

You place a control onto your page:

<asp:Content ID="Content1" ContentPlaceHolderID="Content" Runat="Server">
	<asp:TextBox Id="Firstname" Runat="Server" />

The output is rendered as:

<input name="ctl00$Content$FirstName" type="text" id="ctl00_Content_FirstName" />

In the example above, the disparity in the rendered id attribute occurs because the TextBox control has been placed within a Content control, as the Page object inherits a MasterPage.

So how can you robustly reference the control using client-side JavaScript, regardless where the control resides?  Using jQuery it’s fairly trivial:

var $firstname = $("[id$=FirstName]");

This little snippet makes use of the jQuery attributeEndsWith selector, as documented here.  Bare in mind that an array is returned, as any control with an id that ends in FirstName will be selected.

.Net, JavaScript

Consume .Net Web service using jQuery

The JavaScript functionality that is injected into .Net pages seems limited when compared to jQuery.

Whilst looking for a way to use jQuery instead of the stock Microsoft client library, I came across this excellent article.

There doesn’t seem to be too much on Web about this subject.  Maybe most .Net developers stick to Microsoft tools, but I like using jQuery for all my client scripting, and would rather not use more than one library.  So as it look me a while to get example code working, I’ve included my efforts.
Continue reading