Using KnockoutJS with SignalR in ASP.NET MVC

KnockoutJS is a MVVM implementation for JavaScript written by Steve Sanderson, in my opinion the author of the best ASP.NET MVC textbooks available. Simply put it lets you bind a JavaScript object model to your HTML UI using a Read more

A MongoDB Tutorial using C# and ASP.NET MVC

In this post I'm going to create a simple ASP.NET MVC website for a simple blog that uses MongoDB and the offical 10gen C# driver. MongoDB is no NOSQL database that stores information as Binary JSON (BSON) in documents. I Read more

Linq To SQL Tutorial

Check out some of my other Linq to SQL posts: EntityBase Inheritance Modifiers with SQLMetal Linq to SQL with WCF Services Linq to SQL Framework (Repository/Business wrapper) ObjectDataSource binding with server side paging and sorting Load Options Generic Framework using reflection This is a basic tutorial for Read more

Creating a Composite Server Control with ASP.NET

Posted on by Joe in ASP.NET, C# | 14 Comments

Download source

When creating web applications with ASP.NET developers will usually create User Controls or Custom Server Controls. User Controls have the ASCX extension and allow developers to group together ASP.NET controls and functionality into a reusable control. Custom Controls are a bit more complex and require the developer to define the html that the control generates as well as all it’s functionality. It is also possible to add child ASP.NET controls to a Server Control and have the control render those child control and maintain their viewstate with little work. 

In .NET 2.0 the abstract CompositeControl class was introduced, which is derived from WebControl but also uses the interfaces INamingContainer, which makes sure all child controls have a unique ID, and ICompositeControlDesignerAccessor which is used to allow the control to render the control automatically at design time based on the child controls. The CompositeControl also ensures that child controls are always created which saves using the EnsureChildControls method that many Custom Control developers will be familiar with. 

In this post I’ll explain how to create a simple Composite Custom Control and how to customise the HTML that it renders. 

Read more

How to select checkboxes in an ASP.NET CheckBoxList using jQuery

Posted on by Joe in ASP.NET, jQuery | 5 Comments

I came across a situation where I needed to make sure at least one checkbox in an ASP.NET CheckBoxList is checked before submitting the page.  Looking at the source each checkbox element created shares the same client ID with a different number at the end, so I needed a way to select all checkboxes where the ID started the same.

Read more

ASP.NET MVC – Using Controller.UpdateModel when using a ViewModel

Posted on by Joe in MVC | 31 Comments

When updating a model in MVC it is common to use the Controller.UpdateModel method.  I recently ran into an issue where I was using a custom ViewModel which meant that UpdateModel could not map the updated data back to my model object. The solution to this was a simple one, but not as obvious as it should be due to intellisense not picking up the method’s overloads when the generic type is inferred. 

Read more

Creating a Delete link with MVC using POST to avoid security issues

Posted on by Joe in Ajax, jQuery, MVC | 6 Comments

It is fairly common to have a list of records with a hyperlink to delete a record.  The problem here is that with MVC the hyperlink will use a GET request to delete a record.  This is a fairly big security issue as anybody can browse to the URL and delete a record from your system.  In this post I’ll explain how you can use the Ajax helpers to create a hyperlink that will call your delete method without using GET.

Read more

Edit in place / inline editing with jQuery, jTemplates and ASP.NET

Posted on by Joe in Ajax, ASP.NET, JavaScript, jQuery | 1 Comment

Download source

In this post I talked about how to use the jTemplates plugin for jQuery. Using my final example in the post I thought it would be cool to try and add some ‘edit in place’ functionality to the table.

For this to work I’ve created a Data Access Layer using Linq to XML. My web service then uses this DAL to save and retrieve my data.

Read more

Linq to XML Tutorial

Posted on by Joe in ASP.NET, C#, Linq, XML | 46 Comments

Download source

This is an introduction to Linq to XML showing how to read, insert, update and delete from an XML file.

Read more

Using the jTemplate jquery plugin with ajax and ASP.NET

Posted on by Joe in Ajax, ASP.NET, JavaScript, jQuery | 17 Comments

Download source

A guy in work introduced me to jTemplates, a template engine plugin for jQuery. It allows you to easily bind JavaScript objects to a defined template and also has some other nifty features.

I’ve found jTemplates to be particularly good when using ajax to display any information quickly and easily.

First I’ll explain how to create a simple template to display data, and then how to use the foreach and cycle features.

Read more

Using jQuery to make ajax calls to an ASMX web service using ASP.NET

Posted on by Joe in Ajax, ASP.NET, C#, JavaScript, jQuery | 17 Comments

Download source

Making ajax calls to an ASP.NET web service using jQuery is too easy.  In this post I’ll explain how to do it!

Read more

JSON Serialization using the DataContractJsonSerializer and C#

Posted on by Joe in ASP.NET, C#, JavaScript | 4 Comments

Download source code

Previously I’d done JSON serialization using the JavaScriptSerializer which is part of AJAX Extensions 1.0, but this is now obsolete.

.NET 3.5 introduced the DataContractJsonSerializer class.  The class sits in the System.Runtime.Serialization.Json namespace which is curiously hidden away in the System.ServiceModel.Web assembly.

The DataContractJsonSerializer can serialize a class that contains the Serializable attribute or any class defined as a DataContract.

Read more

Linq to SQL Tutorial – Linq to SQL Generic Framework using reflection

Posted on by Joe in ASP.NET, C#, Linq | 1 Comment

Download source code

In a previous post; Base Repository/Business Logic wrapper, I talked about a basic Linq to SQL Framework I created. I then extended it in my ObjectDataSource binding with paging and sorting post to show how to use it with the ObjectDataSource.

The problem was that although it worked quite nicely for getting all records and getting by ID, if I wanted to perform any specific filtering I had to create a derived repository class with a specific method for each query.

In this post I’ll explain how I have extended this framework using reflection to allow filtering on multiple columns without having to created separate repository objects.

Read more