Wednesday, 29 November 2006
Problems with the AJAX AutoCompleteExtender (arrgh)
I was interested to see that Atlas/AJAX
has now made it to Beta 2. I looked at it earlier in the year but didn't have time to really get stuck in. So today i eventually got it working in conjunction with LINQ
. I wanted to get a basic AutoComplete thing working off my database, with which i am hopefully going to use LINQ throughout.
First of all, go to http://ajax.asp.net/
and download and install the 3 bits they recommend.
Getting the darn thing to workBrad Adams
has a very good getting-started example on this post
, i used his article as a starting point, but i had to sort out a few other things first. i couldn't get any documentation on the AutoCompleteExtender so i scavenged some crucial facts off the net after a lot of fumbling around, i've listed these below. One mistake i made was to start testing the AutoComplete control before making sure that the web service was returning correct data, my LINQ query was chucking exceptions and the AJAX control doesn't give you any feedback on exceptions, which is understandable and probably desirable.
- you must mark your web service class with the [ScriptService] attribute, you'll need the Microsoft.Web.Script.Services namespace for this.
[WebService(Namespace = "http://whatever")]
public class AjaxService : System.Web.Services.WebService
- you need two parameters in your web service method, the naming of the parameters is crucial:
public string GetList(string prefixText, int count)
- if you're using Linq, and if you're new at it like me, you might have trouble getting your LINQ query results into a string array for the web service. I tried returning IEnumerable<TableName> and List<string> etc. but it didn't like that, i ended up using the ToArray() extended method that is part of System.Query. Here is the query i used which concatenates some columns from the table into a collection of strings.
IEnumerable<string> ds =
from r in MyDataBase.Restaurants
select (r.RestaurantName + "," + r.Address1 + "," + r.County); // join the name + address in a string
string results = ds.ToArray<string>();
Formatting the AutoCompleteExtender
The control has some nasty hard-coded values, but where there's a will there's a way. Thanks to the Firefox dom inspector and the CSS !important modifier, all is not lost.
The control does have a property called CompletionListElementID which specifies the container element where the results are inserted. I put a simple DIV next to the textbox:
<div id="AutoComplete" runat="server"> </div>
Then in my stylesheet i have the following values to override the hard-coded styles set by the control:
width: auto !important;
overflow: visible !important;
font-size: x-small !important;
In case you're wondering, the control renders each result as a DIV inside your specified element. The control applies the following styles to your specified element:
border: 1px solid buttonshadow;
You can override whichever ones you want by applying the !important attribute inside the #AutoComplete entry in the style sheet. The individual items then can also be styled via the #AutoComplete div entry, i prefered a slightly smaller font size because the default setting looked too big.
Wednesday, 29 November 2006 16:54:25 (GMT Standard Time, UTC+00:00) Asp.Net
Tuesday, 10 October 2006
A generic Swap function
if i ever forget how to write this function then... well, let's hope i never do. i was really surprised not to be able to find it in the SDK. i'm posting it here for reference anyway. note: this can only be used in .Net 2.0 which supports generics.
Tuesday, 10 October 2006 16:55:31 (GMT Daylight Time, UTC+01:00) .Net General
/// Swap 2 objects
public static void Swap<T>(ref T first, ref T second)
T tmp = first;
first = second;
second = tmp;
Saturday, 07 October 2006
HowTo: Deploy Crystal Reports for VS 2005
i found this insanely difficult because none of the supposedly normal options worked. merge modules didn't seem suitable because i just wanted to install the CR dlls once and for all on the server. according to an MSDN2 article
i should be able to perform a windows installer deployment, but of course when i copy the key code from the VS2005 > Help > About dialog, and use it in the installer on the server, the error message is that the key code has expired or is invalid. 'business objects' appear to be forcing users into an upgrade path for their new product, by claiming that a 'compatibility upgrade' is required for VS 2005, which of course you have to fork out for. such a load of crap.
anyway, what eventually worked for me was to go back into my VS 2005 dev machine and create a web set up project. go into the project properties and click the prerequisites button, select CR for .Net 2.0 and then just build the empty setup project. if you look in your output folder, there is an installation file called CRRedist2005_x86.msi. Just whack this onto the server and your crystal reports should run fine, i didn't need to reboot or restart IIS. Note there is no also need to copy any of the CR dlls to your web site bin folder.
yet another miserable failure for crystal reports!
Saturday, 07 October 2006 01:32:30 (GMT Daylight Time, UTC+01:00) .Net General | Asp.Net | Windows Server
Thursday, 05 October 2006
HowTo: Automate SQL Express Backup
There is a thoroughly excellent article about this on the SQL DBA Tips web site. Don't forget to enable modify permissions for the account that is running SQL Express, e.g. Network Service.
just posting it here in case i ever forget where it is.
Thursday, 05 October 2006 11:31:25 (GMT Daylight Time, UTC+01:00) Database
Friday, 08 September 2006
Wednesday, 06 September 2006
FIX: VS2005 Unrecognised tag prefix or device filter
I encountered this error after upgrading a web site to VS2005 and converting it to a Web Application Project. the project built without problems, it was just the designer kept throwing up errors in the error list which was very annoying.
Thanks to 'ratureus' for his post on http://forums.asp.net/thread/1212425.aspx
- Close VS 2005
- delete all files in C:\Documents and
- Restart VS 2005
this worked for me.
Wednesday, 06 September 2006 11:50:04 (GMT Daylight Time, UTC+01:00) Asp.Net
Tuesday, 05 September 2006
PDF problems: File does not begin with %PDF
I use exported crystal reports in PDF format on my web site, and i was getting intermittent errors from a small number of users. I couldn't reproduce it, and i found a thoroughly excellent article on the problem at the Fluid Components International
They explain what's going wrong and have some suggestions to fix it. I suspect in my case it was a problem with embedding the PDF in an activeX control. i'll just redirect users to download the file instead.
Tuesday, 05 September 2006 15:29:49 (GMT Daylight Time, UTC+01:00) Asp.Net
Wednesday, 30 August 2006
Wednesday, 30 August 2006 17:12:43 (GMT Daylight Time, UTC+01:00) Asp.Net
* Textarea Maxlength script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
<textarea maxlength="40" onkeyup="return ismaxlength(this)"></textarea>
Wednesday, 16 August 2006
Global country list
i took this off Wikipedia
and trimmed it down to plain text for a database. just posting it here for reference:
You may be more interested in the ISO official list of countries
and their 2-digit codes.
SBA Akrotiri and Dhekelia
Antigua and Barbuda
Saint Helena Ascension Island
Bosnia and Herzegovina
Central African Republic
Cocos (Keeling) Islands
Isle of Man
Northern Mariana Islands
Papua New Guinea
Pridnestrovian Moldavian Republic
Saint Kitts and Nevis
Saint Pierre and Miquelon
Saint Vincent and the Grenadines
São Tomé and Príncipe
Trinidad and Tobago
Tristan da Cunha
Turks and Caicos Islands
United Arab Emirates
Virgin Islands (British)
Virgin Islands (United States)
Wallis and Futuna
Wednesday, 16 August 2006 16:39:04 (GMT Daylight Time, UTC+01:00) .Net General | Asp.Net | General
Friday, 11 August 2006
Crystal Reports: Export PDF irregularities between server and dev machine
I have a few reports in my web application that i export in PDF format only. You would think this would remove any printer driver complications but apparently not.
Crystal Reports have a surprisingly good article
to help troubleshoot issues with printing or exporting a report.
The problem i was finding was that in a Text object or Unbound field, the text would be truncated at the edge of the box boundary. Some users have reported strange mid-word wrapping, but mine was a different problem, actually hacking off the end of each line. This didn't happen on my dev machine, but it did happen on the server (2003). When i compared them side by side, the Times New Roman font on the server was stretched by about 5% compared to my dev machine.
with the help of the CR article, i tracked it down to the lack of any printer installed on the server, i had also disabled the Print Spooler service which was preventing even the Microsoft Office Document Imaging Printer from being available. So i started the print spooler service and made sure that the Office Imaging Printer was marked as the default printer. Then i went back to Visual Studio and set all the reports to use the Office Imaging printer. This solved the problem.
You could of course install a PDF only printer such as PrimoPDF if you didn't have MS office installed on the server. As long as the server has the same printer installed as the one set in the report design, everything turns out fine.
Friday, 11 August 2006 13:20:57 (GMT Daylight Time, UTC+01:00) .Net General | .Net Windows Forms | Asp.Net