Wednesday, 22 December 2010

List.Sort() alphabetically

I was faced with the challenge today of sorting a list of objects, where one of the properties was a string. My objects were lists of keywords, and I wanted to sort the keywords alphabetically.

I came across some example of lambda expressions, and found that rather than having to write complicated sort methods for my class, I could just do the following:

keywords.Sort((a,b) => String.Compare(a.keyword, b.keyword)):

Awesome, works a treat!

Wednesday, 24 November 2010

SQL Server could not spawn FRunCM thread. Check the SQL Server error log and the Windows event logs for information about possible related problems.

I encountered this error this morning when my SQL Server instance wouldn't start after I made some connection changes yesterday. I had to make the changes because a needed an ODBC connection, and that would only seem to work if I configured it to use named pipes.

After checking the logs, I received the error "SQL Server could not spawn FRunCM thread. Check the SQL Server error log and the Windows event logs for information about possible related problems.".

So, I went back to undo each change I had made, and noticed that the last change I made was to enable VIA as a protocol for my SQL Server instance. Disabled that, and hey presto, SQL Server now starts fine.

The strange thing is that enabling VIA in my SQL Express instance didn't seem to cause the same issue on that server though.

Tuesday, 27 April 2010

asp.net checkbox modalpopupextender checkbox doesn't check or uncheck

There is an apparent bug in asp.net that when you have a checkbox inside a panel that is acting as a modal popup with the modalpopupextender, that when you try to check or uncheck it, it doesn't work!

I found the following thread, and it seems that quite a few people have had this very same problem.

From reading many posts, it seems that this happens if you do not set the TargetControlID property of the extender correctly.

However, this becomes an issue if you have multiple links, all that show the same extender. To get round this, you can simply create a fake button:

asp.net button not posting back

I have a modalpopup extender attached to a panel, inside which resides two asp.net buttons. Each of these had the normal "Onclick" attribute assigned to them. However, when they were clicked, no postback was occuring.

From some reading around, it appears that this is by design, and that the buttons are there for this to be closed.

So how do you get round this?

You can attach a javscript client side event that mimmicks the behaviour of what happens with asp anyway, by forcing the postback to take place.

Firstly, in the head of your page, define a function that ensures that the page is valid first, and then causes the postback to take place (the validation part is crucial for this to work.

function doPostback(sender,e)
{
if(Page_IsValid)
{
__doPostback(sender,e);
}
else
{
return false;
}

}

Now in your code behind, tell your buttons to call this:

btnSaveUserDetails.OnClientClick = "javascript:return doPostback('" + btnSaveUserDetails.UniqueID + "');";

It is important here that the uniqueID is used, as this ensures that any controls that are nested pass the right details to the postback function.

And ta da, they now work!

Monday, 26 April 2010

modalpopupextender event fires but does not show

I lost half a day of my life to this silly mistake today.

I had on my page a panel, with a modal popupextender. When I clicked a link that ran a serverside mdlPopup.show() or a client side $('mdlPopup').show(), the events fired, but no modal popup showed.

The reason for this was because I had set the "visible" attribute of my panel to "false", rather than setting the style of it to "display:none"!

Silly....

Tuesday, 30 March 2010

The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)

When starting IIS 7 under Vista or Windows 7, you receive the error from the IIS Manager saying "The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)"

The reason for this is well documented, and it is because you have another site setup with the same binding - in english, this means you have two sites setup that are configured to use the same port (probably 80).

In my circumstances, this was confusing because I had only one IIS instance and this was bound to port 80, but wouldn't start.

So, to find out what was conflicting, I went to the command prompt and typed:

NETSTAT -ano

This showed an entry of address 0.0.0.0 using port 80 up!

This also showed the process ID of 4400, so I looked in task manager and found that this was Skype.exe

After digging through the advanced settings in Skype, it appears that by default, Skype decides to listen on ports 80 and 443 for incoming connections (probably to appeas firewalls), so unticking this allowed my IIS to start.

Useful to find out, but it took a while!

Tuesday, 5 January 2010

ie don't print filename

I needed to convert a webpage into a pdf today, and using PDFCreator, this is normally a doddle.

However, whenever I did, it printed the address to the footer of the page.

After much faffing around, I found that under the page setup are "headers" and "footers". If you delete what is in those fields, it stop ie and firefox printing the filenames and page numbers.