Monday, April 02, 2007

I've just fixed a strange bug I was having when comparing a web page in IE and Firefox. The page simply had a single textbox, and a button. By default, in accordance with W3C standards, both browsers will post-back to the server when the user hits <Enter> from within the textbox.

Just the behaviour I wanted, except that when the post-back occurs from IE, the button's event handler does not get triggered on the server!! Very strange ... but this article on 4guysfromrolla.com gives a great explanation.

Basically, IE does not post-back a fully serialised form if there is only one textbox on the page! The server does not know what triggered the post-back and so cannot call the correct server-side event handler. The workaround? ... add another textbox to the form (but just make it hidden!).

This is true for IE6 and IE7 ...

posted on 4/2/2007 4:13:27 PM (New Zealand Standard Time, UTC+12:00)  #    Comments [0]
 Monday, March 26, 2007

I wanted an animated give for an AJAX application I am working on and was struggling to find anything until I stumbled upon http://www.ajaxload.info. Very simple site (work in progress?) but it gave just enough options to create just the "Wait Image" I needed.

posted on 3/26/2007 9:32:08 PM (New Zealand Standard Time, UTC+12:00)  #    Comments [0]
 Thursday, December 07, 2006

When using the GridView, you can specify an “EmptyDataTemplate” to display when there is no data specified in the DataSource. This is great, but the problem from my point of view is that the column headers are not displayed. I would like them to be displayed, even if there is no data.

In my search for the solution I found the following article which explains how to achieve this result by overriding CreateChildControls:

http://www.dotnetslackers.com/GridView/re-27953_Displaying_GridView_When_No_Data_Exists.aspx

 

posted on 12/7/2006 6:22:08 AM (New Zealand Standard Time, UTC+12:00)  #    Comments [0]
 Tuesday, November 28, 2006

To support Web Farms (multiple machines) or Web Gardens (multiple processors), changes to the ASP.NET configuration will need to be made. Thankfully this is just configuration; no code changes would need to be made.

The main thing to be aware of when setting up for a farm/garden is that a user's request can hit any processor or server. As such, the user's session needs to be available across the entire farm/garden and so session state cannot be held locally in memory, which is the default configuration.

The following links give further details on what can be involved:

Session-State modes: http://msdn2.microsoft.com/en-us/library/ms178586.aspx
Web Garden Model: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/dngrfTheASPNETHTTPRuntime.asp

posted on 11/28/2006 7:23:57 PM (New Zealand Standard Time, UTC+12:00)  #    Comments [0]
 Tuesday, November 21, 2006

It's not an error message that you see often when working with ASP.NET, but if you’re deploying to a new, clean machine, it can happen quite easily.

Failed to access IIS metabase screenshot

The problem comes around due to the order that components were installed on the machine, namely that The .NET Framework was installed before IIS. As a result, ASP.NET is not correctly configured to run. The easiest way to rectify this is to re-install ASP.NET with IIS.

aspnet_regiis –i

If you only require default settings then this is the easiest option. The Microsoft KB specified in the error message suggests the –ga switch, but that requires a little more knowledge of the Windows system as it requires you to specify the Windows User Account to run under (which is different between Windows 2000, XP, 2003, etc). Easier to simply use the –i switch!

posted on 11/21/2006 5:46:12 AM (New Zealand Standard Time, UTC+12:00)  #    Comments [0]
 Friday, November 17, 2006

When you're developing and testing your system, you'll want to test that any emails sent are actually being sent to the SMTP server correctly: the html format is all ok; email from and email to are correct; etc.

 

An easy way to do this is by configuring .NET to drop the emails you send to a specific folder. As long as you’re sending your emails via SmtpClient and are configuring it via the web.config file (if not, why not?), the following configuration section will set up the email folder:

<system.net>
   <mailSettings>
      <smtp deliveryMethod="SpecifiedPickupDirectory">
         <specifiedPickupDirectory pickupDirectoryLocation="C:\Temp\EmailPickupFolder"/>
      </smtp>
   </mailSettings>
</system.net>

If you then browse to the folder, you’ll see files like below. When opened in notepad, you’ll see the email in it’s raw format, or if you need to check any Html formatting, you can open it in Outlook Express.

 

Notepad View

Outlook Express View

posted on 11/17/2006 12:04:22 PM (New Zealand Standard Time, UTC+12:00)  #    Comments [0]
 Tuesday, August 29, 2006

The answer is that in ASP.NET, static variables should be used instead of the Application object. It's something that I had never considered in terms of best practice, until I was asked this week. After a little digging on MSDN I came across the guidelines which state:

  • Use static properties instead of the Application object to store application state.
  • Use application state to share static, read-only data.
  • Do not store STA COM objects in application state.

It comes down to the fact that the Application object is included for compatibility with classic ASP which had no application runtime like .NET.

You learn something new every day! More info can be found in the Knowledge Base article 312607.

posted on 8/29/2006 9:35:04 PM (New Zealand Standard Time, UTC+12:00)  #    Comments [0]
 Saturday, July 22, 2006

This is something I always forget how to do. When you use the Response stream to output a file or image, you often want the name of the stream to make sense. That way, if the user tries to save the file or image, the suggested name is what you specified.

Before ending the Response stream, add something like the following:

context.Response.AddHeader("Content-Disposition", "inline;filename=" + _filename + ".png");

posted on 7/22/2006 8:16:45 PM (New Zealand Standard Time, UTC+12:00)  #    Comments [0]
 Monday, July 10, 2006

A problem I had recently was that a GridView bound to a SqlDataSource was not deleting the records when the Delete command was executed. I've tagged this entry as a "gotcha" as it isn't completely obvious where the problem might be to the uninitiated.

The Delete Sql command was executing fine, but after using SqlProfiler I noticed that the “ID” parameter was set to “Null”, hence the fact that no record was deleted. This was not what I expected as I had used the normal SqlDataSource and DataGrid wizard to set up the controls. What I was missing was setting the “DataKeyNames” property on the GridView to the name of the primary key of my data … “ID”. Now, the SqlDataSource passed through the correct Sql statement and all was good!

I’ve avoided the SqlDataSource/Designer approach whenever possible for the very reason that it’s difficult to see what’s going on when something doesn’t work. I was creating a prototype so time pressures won out and I used it!

posted on 7/10/2006 8:16:04 PM (New Zealand Standard Time, UTC+12:00)  #    Comments [1]
 Saturday, July 01, 2006

The first Sql Everywhere CTP was realeased early this week which brings the Sql Mobile world to the desktop. Anyone familiar with working with the .NET Compact Framework and Sql Mobile will know the problems creating automated tests for a database application. The fundamental problem has always been that the database needed to be hosted on a device or emulator. Now, we'll be able run and test data access code on the development machine.

All this is great, except that it's not supported for ASP.NET applications! Steve Lasker from Microsoft has a blog post that highlights the design decisions around this, but I can't help thinking that it was a little misguided. What's the problem with a hosted environment? When a website needs to hold only a little content in a db, why should we have to use Sql Express? This is especially a problem in a place like NZ where hosting companies want to charge you a fortune for just 25Mb of Sql space.

Just to make sure, I tried creating and connecting to a database in ASP.NET. Surprisingly it let me create the database but it didn't let be read from it.
posted on 7/1/2006 11:54:29 AM (New Zealand Standard Time, UTC+12:00)  #    Comments [0]
 Monday, June 26, 2006

It's taken a while, but I finally found a blogging system that I liked.

ThinkJot is an ASP.NET 2.0 version of the latest release of the dasBlog engine. The reason for the split is that when running under ASP.NET 2.0, your site is running by default under "Medium Trust" rather than "Full Trust", which was the case in .NET 1.1. If you're running on a shared host as I am here, you'll probably find that it is running under the default security settings. No problem you think ... well, try running dasBlog 1.8 under "Medium Trust" and you'll find it doesn't work! It turns out that even things such as the date picker used, did some things that needed to run under Full Trust. For the full story go to the blog.

That's where ThinkJot comes in. It was simply a rebuild and tweak to make it ASP.NET 2.0 and Medium Trust friendly. I pass my thanks on now to the guys at Process64 who did this, you saved me a job!

posted on 6/26/2006 10:23:58 PM (New Zealand Standard Time, UTC+12:00)  #    Comments [0]