msgbartop
The power of thought
msgbarbottom

04 Nov 08 Interesting ad

Had a meeting at the wine loft, saw this.

Tags:

02 Apr 08 Blog upgraded to WordPress 2.5

Yep, It’s 2.5 now!

 

27 Mar 08 ASP.NET Ajax CalendarExtender cause bizarre error on pages upgraded from 1.1

Adopting CalendarExtender in the application we upgrade from asp.net 1.1, keep getting following error.

Entered text cannot contain HTML sequences like <NAME> for security reasons. If you need to use > or <, ensure that there is a space between it and any other characters.

System.Exception: Invalid input was detected by .NET — use validateRequest=false to allow

Upgraded the web.config to enable ajax behaviour etc, that we know to ajaxify an existing application. What else?

Accidentally, we found this error doesn’t occur to some other Ajax tool kit controls such as AlwaysVisibleControlExtender, Strange!
Suddenly, we realized <head> tag on the upgraded page doesn’t have runat=”server” attribute. (By default, head is runat server from 2.0). This might do it.

Put it on, problem goes away. Magic!

Why? Reading the html source, we found ASP.NET truck a CSS style sheet for CalendarExtender control before </head> tag, without runat=”server”, head is invisible in code behind. Fair enough!

Tags:

27 Mar 08 Use Lambda Expression in List(T).ConvertAll()

Lately, I have been upgrading an asp.net solution from 1.1 to 3.5. Kept being amazed by the richer functionalities brought be C# 3.0. It is Lambda expression this time.

Generic List defined a method ConvertAll which convert all element in the list into a new type. This is a sample shows what you can do with it in 2.0

 With Lambda Expression, here is the above code turns into

 

Neat eh!

Tags:

15 Mar 08 Presentation at Datacom

Had a 30 minutes presentation at Datacom during lunch last friday, it went really well.

The reason I said that is after tallking to people who attended the presso, I know they get something out of there. that’s the key thing of a presentation.

Compare with the one I did in .NET user group week before, this is longer, covered more areas of LINQ to SQL, and most importantly, I included lots of more tips and tricks that I found out about the technology which I am sure people will bump into these sooner or later.

I remember that one trick that Dale always use in public speaking is know what you are talking about and tell people your real experience. and this is one true great advice.

I am still a bit of short in controlling my nerves during the presso. I used much much more eye contact, people feel me talking to them rather than the computer, it’s some progress there. oh, one thing, I am a little bit over on time, about 10 minutes more than I expected and I forgot to let people ask questions I am sure they must have some.

hey, it’s only my second one, I am sure I will get better and better. so looking forward to my next one.

Tags: ,

06 Mar 08 Presentation at .NET User Group

Last night I did a short presentation on LINQ to SQL at Wellington .NET User Group. I was lucky to have the opportunity to present along side of some well recoganised industry presenter such as Jeremy Boyd, Kirk Jackson etc. It’s very short and brief, but it’s a great way to start and I am definitely looking forward to doing more presentations in the future.

Had a very intresting chat with Scott who also presented on the same day. Funny enough, we have an extremely similar view on blogging. Over the years, Scott has always been an inspiring character. I truely learned a lot from him.

Tags: ,

17 Feb 08 DataLoadOptions.LoadWith(T)

Defer loading is a great feature of LINQ to SQL, but sometimes you may just want to pre-load an Association property of a primary class even when it’s not referenced. This is called immediate loading in LINQ to SQL. You can do this by providing an instance of DataLoadOptions to your DataContext object. To the instance, you specify what to load with by calling LoadWith<T>() method. here is an example.

Tags: , ,

26 Jan 08 ASP.NET Unit Test in Visual Studio 2008

I was really suprised when I realize I can generate a unit test case for a private method defined in .aspx in Visual Studio 2008. It is really simple, right click the method you want to test for and select “Create Unit Tests…”

On the Create Unit Test popup, you can select other class/method you want to test. You can also specify test project in which the test class is created by selecting Output Project dropdown option

 If you want to specify the test file name, test class name and test method name, you can do so by clicking the Settings… button. [Class] or [Method] is the place holder for the base class and method you are creating the test for.

It is that simple. VS 2008 generates something like this

The HostType and UrlToTest attributes are used for test project running the ASP.NET test case under the same environment the production code will run. It loads settings from web.config file from you ASP.NET application, this is really cool, think about the old school of creating a app.config file with duplicate settings in your unit test project. You can find more detailed explaination of how ASP.NET unit test works here and there.

Strange enough, you might get the following error if you run the test case just like that.

The test adapter ‘WebHostAdapter’ threw an exception while running test ‘TestCreateUser’. The web site could not be configured correctly; getting ASP.NET process information failed. Requesting ‘http://localhost/MyWebSite/VSEnterpriseHelper.axd’ returned an error: The information returned is invalid.

The reason is ASP.NET test case is running using the same security model as the application, VSEnterpriseHelper.axd can only be accessed by authenticated user. To solve this problem, add the following code in your web.config file.

Tags: , , ,

26 Jan 08 Mailbox unavailable. The server response was: 5.7.1 Unable to relay for x@x.com

If you use MailMessage + SmtpClient sending email through localhost in your .NET 2.0 application and getting this error, here is the answer

Tags:

17 Jan 08 Insert/Delete using LINQ to SQL in Visual Studio 2008

In Part 4 of Scott’s LINQ to SQL series early last year, there are code samples demonstrate how to insert and delete from database by using NorthWindDataContext (extended from DataContext).

I followed the same approach, come up the following code.

You may wondering where has Add method gone? I asked the same thing. After an intensive research (even tried Reflector), I realize Add/RemoveAll have been removed from System.Data.Linq.Table<TEntity> class. There are InsertOnSubmit/DeleteAllOnSubmit to replace them.

I replaced line 32 with “db.ToDoItems.InsertOnSubmit(todo);” and ran the test, check the database, record has been inserted.

Tags: ,