Friday, 26 February 2010

Windows 7 - First Impressions

I have the privilege to now have a Windows 7 desktop at work. I want to find out whether it runs all my development software etc. Anyway, a guy here installed Windows 7 Professional on this new Dell Optiplex 780 (Core 2 duo 3GHz 3.25 Gb usable RAM) and installed Visual Studio 2005, 2008 and SQL Server 2005. He setup the domain configuration etc and then gave it to me to finish off. So far I have tried to copy files from my old PC to my new one via a network share, install MS Office and carry out Windows Update. Here are my results (not great I'm afraid).
I have had lots of problems with the network. This machine has an Intel Gb card connected to a 100Mb hub on my desk into the network. It basically works but it seems when I am doing a lot of network intensive stuff (windows update and copying files) the network fails, the copying fails and the only thing I can do is reboot to fix it. I tried logging off and on and then the system froze on login.
A second problem was related to using VMWare Client which for whatever reason doesn't currently support Windows 7. I found a workaround that required modifying a config file under program files. I have admin access to the whole PC so I clicked Open With on the file, opened it in Wordpad and then tried to save it. "Access Denied". I tried tacking ownership and all sorts of things. "Access Denied". I have full access to the directory and can create/delete/copy things but cannot modify the file. There is no option to "Open with .. as administrator". Another x for MS, they still haven't got this security thing worked out. Anyway, I worked around it by copying the config into Documents, editing it and then copying it back. How ironic that I cannot save the file but simply move it elsewhere and do the same thing (this is not obvious). After doing this, I created a batch file as per the original workaround and tried it out, no probs. I then rebooted and tried to link my desktop shortcut (to the original exe) to the new batch file and lo and behold, it had been removed by the system. Again, a poorly thought out security system that simply doesn't work. What am I supposed to do? Some horrible hack? Turn off the security to make it work? Spend hours trying to fix it? NONE of this is intuitive.
The other thing and it exists on other software is the Knight Rider progress bars. Windows Update has one. The point of a progress bar show progress, not to swish from side to side which means nothing whatsoever (it doesn't mean anything is actually happening, just that Windows hasn't locked up). Come on MS, a download progress bar is easy.....

Wednesday, 17 February 2010

Ajax Control Toolkit AutoCompleteExtender problems

I have used this autocomplete control and to be honest it seemed to work pretty much as expected. However, I had originally coded it into a specific page and wanted to make it into an user control so I could use it all over the place. I had problems though so here are the things I had to do to make it work:
  1. Move the service method from the class to a web service (I already had one so I added it to that). Make sure that the web service is marked with [ScriptService] and the method with [ScriptMethod] I also marked it as [WebMethod] just for fun.
  2. This method when in a web service MUST be non-static and although it can have any name, it MUST return a string[] or List and MUST have two parameters that are of the type AND NAME: string prefixText, int count since the reflection system uses the names to look these up (messy but that is how it is!)
  3. For some reason I couldn't use a server tag to insert the unique ID of my text box control into the TargetControlID of the autocomplete control since it would be mangled inside a master page. I therefore added the code: autoCompleteExtender1.TargetControlID = enterSearchNumber.UniqueID; into the Page_Load method inside my user control. This is NOT inside if (!IsPostBack) so that it links every time.
  4. I created an event in the user control that is fired when the user presses a "Load" button using the normal EventArgs type technique and which returns the selected object in the event args.
  5. I set the ServicePath property of the autocompleteextender inside my UserControl to (in my case) servicepath="~/Quotation/BusinessLogicAccess.asmx" and also obviously set the servicemethod property to the name of the function.
  6. Then since it is used inside an UpdatePanel for Ajax, I had to add the following inside my ScriptManager:
Other than that, it was the normal UserControl stuff like using @Register in the control to link to the AjaxControlToolkit.dll and using it as normal.

Monday, 15 February 2010

Text boxes and Text areas not posting back

I have a page with some text boxes that the user can change in the rows of a datagrid. Because however there is potentially a lot of text, the datagrid row only displays a small box with about 30 characters and an edit hyperlink brings up a JQuery dialog to edit the text.
The problem I had was that when I updated the row, even though the text was displayed in the small textarea, it was seemingly not posted back and not updated.
I thought it was some funny datagrid thing or viewstate but then I noticed that the values for quantity and item (a select) were posted back so something was wrong.
Simply problem, because the text areas were set to enabled="false" the browser (or the standard) wrongly assume that they can't be modified and don't bother posting them back in the querystring. Instead I had to use readonly="true" which works but doesn't look the same as a disabled text box. Potentially quite a hazrd for someone who literally loads an item, sets all the fields from what he thinks the datagrid is displaying and then overwrites it all!
UPDATE: Setting read-only to true does NOT work. It causes the value to be passed back in the querystring but ASP still ignores the changed value. I think what i will do is leave the box enabled but handle the onclick handler to display the full-size edit dialog! Nice. I could also cover the text boxes with transparent divs but that is one of those things I don't really want to do!

Wednesday, 3 February 2010

Event Handler not called from DropDownList

Had a really annoying problem with an site, one of those things that turns out to be really simple yet takes ages to track down. I have a master page with a script manager and update panel and then a contentplaceholder inside the update panel so that the content area of all new pages on the site can have ajax for free. People talk about large overheads etc but quite simply the updates are much snappier with the update panel and you get a free 'waiting' dropsheet if it takes a while to do.
Anyway, in my page, I had a dropdownlist with a list of categories in it and an event handler connected to onselectedindexchanged, I set autopostback to true but although i could get the postback, the page would not call the event handler. I assumed it was a combination of Ajax and master pages but it was much more simple.
The data I had bound my list to was a collection that expects an int (for datavaluefield) and a display string for the datatextfield. Since my data did not have unique ids, I returned zero for each value. What happened then? Well since the value didn't change when I changed the dropdownlist, the system didn't detect that the selected index had changed and didn't call the event handler. It would have been more obvious if the event was called onselectedvaluechanged since the form only posts back the selected value and not the index but anyway, hope this helps someone else.