CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Peter's Gekko

public Blog MyNotepad : Imho { }

September 2005 - Posts

  • MSDN now offers Vista beta2, build 5219

    I keep correcting myself. MSDN now has the PDC build of Vista, no longer the previous beta1 is still there as well.
  • Disable an asp.net LinkButton (or HyperLink) without graying it out

    I have a web form with a couple of linkbuttons. The linkbuttons serve as tab selectors, clicking one will activate an associated panel. When a panel is selected I don't want the user to select it again, clicking the linkbutton would be an unnecessary roundtrip. I can set the button's enabled property to false but the now the button will be grayed out. But this does not fit the user's impression of having precisely selected that tab.

    Many asp.net controls have the AutoPostback property to disable an unintended postback. A linkbutton does not. But there is a very simple way to knock out postback with a snippet of script. This code does exactly what I want

    LinkButton1.Attributes["OnClick"] = "return false;";
    LinkButton1.CssClass = "HighlitedTab";
     

    It sets the clientside click handler to the JavaScript statement return false; Which cancels postback. The appearance of the linkbutton is changed by setting its CSS class, so the user is informed about the status of the button. Both the attributes and the cssclass are included in the linkbutton's viewstate. To restore the control's original state on the next roundtrip you need to reset it from code or disable the control's viewstate.

    This also works for a hyperlink. But I do not see a meaningful use for it there. Yet.

  • ISO weeknumbers of a date, a C# implementation

    The DateTime class in the .NET framework is very rich in methods for manipulating and computing dates. In my former language Delphi working with dates was no fun. All had to be done by manipulating strings but given the fact that nobody can agree on what comes first, day or month, all code was tricky and prone to bugs.

    The only thing which is missing in the class is a weeknumber property. Every workweek has its own number. In Europe this is very often used. There is an ISO 8601 standard which describes how this number is calculated: Week 01 of a year is per definition the first week that has the Thursday in this year, which is equivalent to the week that contains the fourth day of January.

    There are plenty of implementations to be found on the web to calculate this number. Finding a good one in C# took some assembling. This one is based on a Delphi implementation on the SDN site. Thanks to the DateTime class it needs only a fraction of the code.

            private int weekNumber(DateTime fromDate)
            {
                // Get jan 1st of the year
                DateTime startOfYear = fromDate.AddDays(- fromDate.Day + 1).AddMonths(- fromDate.Month +1);
                // Get dec 31st of the year
                DateTime endOfYear = startOfYear.AddYears(1).AddDays(-1);
                // ISO 8601 weeks start with Monday
                // The first week of a year includes the first Thursday
                // DayOfWeek returns 0 for sunday up to 6 for saterday
                int[] iso8601Correction = {6,7,8,9,10,4,5};
                int nds = fromDate.Subtract(startOfYear).Days  + iso8601Correction[(int)startOfYear.DayOfWeek];
                int wk = nds / 7;
                switch(wk)
                {
                    case 0 :
                        // Return weeknumber of dec 31st of the previous year
                        return weekNumber(startOfYear.AddDays(-1));
                    case 53 :
                        // If dec 31st falls before thursday it is week 01 of next year
                        if (endOfYear.DayOfWeek < DayOfWeek.Thursday)
                            return 1;
                        else
                            return wk;
                    default : return wk;
                }
            }
     

    The nice thing I used from the Delphi sample was the iso8601 correction array using the day of the week as index.

    It would be even nicer to add the method as a property to a derived DateTime class. Alas that class is sealed.

  • The availability of Vista beta's

    In yesterday's post I raised the impression that I downloaded Vista beta 2 and its product key from MSDN. I have to correct that, my beta 2 was obtained on the Vista beta site (no link, it's not public :(). This site uses the same download tool as MSDN but is not as chaotic as the new MSDN site (I'm still not used to it..) and a lot faster. The MSDN beta appears to be still beta 1. Which explains why my key did not work. The beta on the beta site is the same build, 5219, as the one in the PDC goods.

    Sorry about the confusion.

  • Installing Vista build 5219 (on a tablet PC)

    Recently I installed Vista beta 1 on my tablet. Not in Virtual PC but as dual boot. You need a dedicated partition for that, but it is the only way Vista can reach your machine's hardware functionality like DX or the digitizer tablet. The first install was nice but not really a tablet, after adding the TIP install it started feeling like the real thing. Despite my tablet having (relatively) meager specs it worked pretty well. I did have the occasional blue screens. As far as I can see these were caused by my external firewire CD drive and by me trying to do something which needs more memory than available; like loading a WPF application in VS 2005. Another way to blow up was trying to assign a read-only property of the InkCanvas in XAMLpad. Although you would expect Vista to fail gracefully in these scenarios......

    Since the PDC there's beta 2, build 5219. I downloaded it from MSDN the beta site. My MSDN product key was refused by the setup. Luckily I had already found an entry in Tim Sneaths blog which provided a product key which worked. Have taken that hurdle setup refused to load the DVD image. Starting the setup from XP, instead of booting form the DVD worked better. The setup itself rolls on unattended but does not install any network drivers;  just the one for the Infra red device. I wasted some time in the Install Supplemental drivers part of Vista. I'm not quite sure but that looks like a little messed up. First of all it was looking for a file DriverRepository.idx, the only thing available was driverre.idx (an 8.3 filename !). Having fed that to the driver installer it was still no success, kept complaining about failing to install. What did work was installing the drivers the classical way. Go to control panel/system/device manager. You can see the missing drivers there. Select update driver and tell Vista you will manually pick a driver from the list. Both my wired and wireless driver were in the list of compatible drivers and setup went perfect.

    Now I have a connected Vista tablet. It does include the InkBall game. Still very nice but it shows that you can get RSI with a pen s well. The tablet functionality in beta 2 is very good. For a good description and review of that I warmly recommend Collin Walker's article. The TIP (Tablet Input Panel) has had quite an overhaul since the first Vista preview. The two sym buttons have turned into a sym button which list quite an impressing list of symbols and a web button which now lists .nl and not .uk. In the control panel I set regional setting to the Netherlands, .nl is our top level domain. The only thing still missing is a handwriting recognizer for the Dutch language.

    There is a setting for touch screens, by default that is switched on. The real new thing for a classical tablet are the flick gestures; see Collin Walker's article for a good review of those. The 5219 build still occasionally produces blue screens on my machine (Acer CT 111) but is on the average smooth to work with; although it sometimes stalls in the TIP. Right now I'm installing the WPF SDK. I don't doubt the traditional ink apps still work, and now I want to see more. To be continued (in the next weekend :)).

  • Programming WCF : Next, next, next, finish ?

    Last Friday, september 16th,  we had a meeting of the SDN user group. As always an enlightening experience.

    The theme was integration Now the SDN is a user group of coders, but with the new tools there is not that much left to code. Take the talk on WCF

    When it comes to WCF enabling your coding it is a matter of setting some attributes and filling in a configuration file. For the latter there are some wizards. One of the speakers jokingly described their IT staff as "Next, Next, Next, Finish" wizard magicians. With WCF and WSE programmers seem to be heading the same direction. The advantage of being a coder is that you are supposed to understand what is going on. So when you fill in your wizard you do know what you're doing. The talks on the meeting did help, but I do feel a little sad on the conclusion.

  • Missed the PDC linq ? Don't read blogs.. watch this

    No I didn't visit the PDC and yes, just like Ben am drowning in the Linq is here blogposts. Instead of reading all that I would recommend this Channel 9 video. In 30 minutes time Anders himself talks from his office about what and why Linq is. Very clear and a delight to watch. Not about OR-mappers and related stuff but about new basic building blocks for the .NET framework. Stay #.
    Posted Sep 19 2005, 06:42 AM by pvanooijen with no comments
    Filed under:
  • A touching gesture

    I missed my chance to come to the PDC and hear this first hand, but blogs can fill the gap.

    Microsoft has announced it will license the current Tablet OS, Windows XP 2005 Tablet PC edition, to touch screen PC makers. Fujitsu already announced one for next month. A touch-screen is by long not as sophisticated as a digital digitizer, when it comes to handwriting you're lucky to reach some level of finger-painting. But the Tablet OS has some things which can do great things for touch-screens. My bets are on gestures. The Tablet OS has a built in gesture recognizer which recognizes movements of the pen (finger) like a circle or an arrow to the right.

    Everybody is used to pushing a button on a touch-screen, steering the mouse pointer by touching becomes stranger. Just imagine some of these possibilities :

    • Drag and drop with your finger
    • Finger stroke to the left, right, up or down. To manipulate or move something
    • Circle your finger around something to select it

    All without the need for any extra controls. With the Tablet OS and its SDK it's no big deal to build this into an application. In this post you can read an overview of and how to work with gestures in your code.

    In Vista tablet functionality has become an integrated part of the OS. Noteworthy are flicks, which is a new system-gesture (see this post for the difference between system and application gestures) intended for browsing, a flick would be the pen (finger) equivalent of the page down key. Vista will also have touch-screen support. Touch and pen support can be in conflict, it's hard to write on a screen without your hand resting on it, and thus touching it. But what about a machine with two screens ? A small one on the outside to list new messages and operate your mediaplayer. Touch would be fine. And a big one inside to write on.

    I'm going to stop before I drown in pure speculation. Just wish I was in LA.

  • Scripting errors on an aspx page, validatorcontrols and causesvalidation ('undefined' is null or not an object)

    The ASP.NET toolbox has some nice validator controls like RequiredFieldValidator and RangeValidator. These perform a first validation of client input in the browser. On postback the validation is repeated on the server. The client side validation is not supported in every browser and is skipped in some scenarios. A side effect of the validation scripts is that a page with validator controls sometimes pops up quite mysterious scripting errors. This is because validation is, by default, performed on every roundtrip. In some scenarios this can lead to invisible controls being validated with null values and script errors like 'undefined' is null or not an object.

    The good thing is that you can disable validation on a control base. Every control which can force a postback, like a button or linkbutton, has the CausesValidation property. Default it is set to true. Set it to false in case there is nothing to validate and your script errors are gone.

  • A way to get rid of infinite code cycles : Cyclebetter.com

    Can't get out of that spiral of cyclic bugs ? Take a break and give you cycle-wheels a spin. It really helps. I already knew many IT people were cyclist. Take Microsoft's Eric Gunnerson. His blog is supposed to be about software, but he cannot always write everything he would like. When he is under a NDA he'll blog on cycling. Also software architecture guru Martin Fowler is passionate about cycling but doesn't blog on that. And to my surprise not just Brendan, also Grant is a passionate cycler. 

    I'm one as well, so when Brendan set up Cyclebetter.com I just couldn't resist. This is the only cross-blog post I'll make. To you coders out there I just want to say: "Ga toch fietsen" and break the code cycle.

  • Beta of the TIP for Vista Tablet PC

    Recently I installed the Vista Beta on my Tablet PC. It works, given the occasional blue screen, quite well; but didn't feel like a real tablet PC yet. The pen worked but the Tablet Input Panel (TIP) and the handwriting recognizers were still missing. There is good news: a beta of the TIP is now available to MSDN subscribers. The TIP does not make much sense without handwriting recognition; in the beta one for the English language is included. My first impressions are quite positive. XP Tablet Edition 2005 could keep up with my lousy handwriting and Vista has no problems either.

    There is no possibility to change the language. What also changed (or isn't included yet) compared to the XP version is context sensitive recognition of handwriting. When you want to scribble a web-address in XP Tablet PC's edition IE the recognition of url's is favored using factoids. Buttons with url specific words like http:// and .com automatically pop up. The Vista TIP has three special character pad's; but you have to select them yourself with a click. This is what the web-pad looks like

    <>

    Note the .uk button.

    The recognizer is also available to your own code. Again I tried my text-reco demo which was build with the tablet SDK (which was originally designed for VS 2003) and VS 2005.

    <>

    Like a charm. Now my Vista Tablet is a real Tablet.

More Posts

Our Sponsors

Free Tech Publications

This Blog

Syndication

News