vendredi 22 octobre 2010

jQuery Autocomplete : set autocomplete field to a value

I struggled to find this and the solution is so simple…

In the select event, you can set the value of the field and if you return false, the value won’t be the selected item.

 $(function() {
source: function(request, response) {
url: '<%= Url.Action("ZipCodeAutoComplete", "Home", new { area = "" }) %>',
data: { term: request.term },
success: function(data) {
response($.map(data, function(item) {
return { label: item.ZipCodel + " - " + item.City, ZipCode: item.ZipCodel, City: item.City }
minLength: 3,
select: function(event, ui) {
return false;

jeudi 21 octobre 2010

Connect to Oracle using NHibernate

Here is my setup to connect to an Oracle database using the ODP.NET provider.

Install Oracle client v9 R2 or greater.

Reference Oracle.DataAccess dll in your project.

Configure your database connection in the tnsnames.ora file. This file is located in $ORACLE_HOME/network/admin/tnsnames.ora.

Configure your connection string in your application. I usually use this syntax:

<add name="default" connectionstring="Data Source=tnsnames_alias;User ID=username;Password=pwd">

Then use the OracleDataClientDriver in your NHibernate configuration or OracleDataClientConfiguration if you use FluentNHibernate.

This should do it!

mercredi 21 juillet 2010

User/role extension methods in an ASP.NET MVC view

This is a small Html helper that I use when I need to check the role in a view

public static class PageHelper
public static bool IsAdmin(this ViewUserControl pg)
return pg.Page.User.IsInRole("Admin");

public static bool IsCustomer(this ViewUserControl pg)
return pg.Page.User.IsInRole("Customer");
Don't forget to add the namespace for your extension methods in your Web.config :
<add namespace="MyProject.Web.Helpers" />

samedi 3 juillet 2010

Blogger open link in new window

In quest for the perfect setup for my blog, I know want to have my links open in a new browser window. The simplest way to do it is to add this tag in the <head></head> part of your template :
<base target="_blank" />

vendredi 2 juillet 2010

Source code syntax highlighting in blogger

I finally figured out how to have syntax highlighting for the source code in blogger thanks to this blog post.
This is the list of brushes I use :
<script src='' type='text/javascript'/>
<script src='' type='text/javascript'/>
<script src='' type='text/javascript'/>
<script src='' type='text/javascript'/>
<script src='' type='text/javascript'/>
<script src='' type='text/javascript'/>
<script src='' type='text/javascript'/>

AvalonEdit in a WPF application with MVVM

According to this forum message, it's not possible to bind the Text property from the Avalon Editor to a simple property of a ViewModel.
Instead, you can use the Document property from the editor and bind it to a property of your ViewModel.
Here is the code for the view :
<Window x:Class="AvalonEditIntegration.UI.View"
        <Button Content="Show code"
                Command="{Binding ShowCode}"
                DockPanel.Dock="Bottom" />
        <AvalonEdit:TextEditor ShowLineNumbers="True"
                               Document="{Binding Path=Document}"
                               FontSize="10pt" />

And the code for the ViewModel :
namespace AvalonEditIntegration.UI
    using System.Windows;
    using System.Windows.Input;
    using ICSharpCode.AvalonEdit.Document;

    public class ViewModel
        public ViewModel()
            ShowCode = new DelegatingCommand(Show);
            Document = new TextDocument();

        public ICommand ShowCode { get; private set; }
        public TextDocument Document { get; set; }

        private void Show()