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

Peter's Gekko

public Blog MyNotepad : Imho { }

December 2004 - Posts

  • Browser peace and where (VS) 2005 can help.

    In a comment on  a recent post on using IE and FireFox to debug ASP.NET apps, Boucher states that it is maybe too far for a peacefull world. The point of my post was that an ASP.NET 1.x app behaves different in IE and Firefox but that an ASP.NET 2 application behaves the same in the two browsers. That is because VS uses a different doctype for a web-page in 2005. One that is closer to “the standards”. That's one step towards peace.

    I don't beleive one browser can replace the other. Firefox is imho nicer when it comes to ergonomics, IE just cannot be missed because too many sites on the web depend on it. Darrel pointed to two nice plugins. One for Firefox to view the page in IE, one for IE to view the page in Firefox.

    Both options are in the right button menu, two views in peacefull co-existence only a click away. That's another step.

    Happy new year.

    Peter

  • Tablet PC junior

    Far fetched ?

    • Both devices have a pen with a static magnet in the tip. Not interoperable.
    • Could you imagine your kid enjoying a keyboard like this ?

    Merry Christmas

    Peter

  • Tablet API : GetDefaultRecognizer() behavior

    The tablet PC is great in recognizing handwriting. But to be able to recognize it needs a language specific recognizer. These are avaliable for several languages.

    In the API is the GetDefaultRecognizer method which returns the default recognizer for the system. The simplest overload does not need any parameters and should return the recognizer for the default language of your system. In my article on tablet development I had already been strugling with it; without a parameter it never returned a recognizer at all. Right now I think I see the problem.

    My tablet runs XP tablet edition US. My regional settings are set to Dutch but my main input language is English-US. The Dutch language is great but not for developing software. But I do want my prices in Euro's and do want the Dutch date-format. Fiddling with these settings it looks like the GetDefaultRecognizer takes the region setting and not the input language. It will try to find the Dutch recognizer and fail. Setting my region to some English speaking country does return a recognizer.

    I think this is a bug, the method should check the input language.

    Peter

  • Password fields

    A small security related item. I'm a lazy typer and love to copy things. Outlook Express makes quite clear that that is not allowed on a password field

    A password on an ASP.NET page (a textbox whose TextMode property has been set to Password) has a similar behavior. It will not pop up the balloon, it just will not copy anything and in rhe tight-mouse menu the copy item is disabled.

    Peter

  • Debugging a webservice with Firefox

    Recently I did some research on using Firefox as browser to debug asp.net webapps. Andre points out in a comment this does not seem to work with webservices. There is one thing you have to watch to debug these.

    When you start a webservice the browser pops up and displays an overview of the service. Clicking a method will fire up a new browser window. Using FireFox you will see a new instance of ff popping up. This new instance is a new process, not the same process the VS debugger had attached itself to and you will miss the breakpoints. But when you invoke the webmethod in a new tab in the same instance of Firefox (right mouse button) the invocation will be in the same process and your VS breakpoints will be hit.

    Peter

    Posted Dec 21 2004, 11:54 AM by pvanooijen with no comments
    Filed under:
  • SDN mobility conference

    Last friday, december 17th, Dutch user group SDN organized a meeting entirely dedicated to mobility. It was lovely; imagine a day spent entirely on Pocket PC, Tablet PC and the like. The presentations went far beyond the usual “hello world” demo's. Especially the .net compact  framework is so straightforward to program that the speakers could focus on real issues as multi-threaded programming, the architecture of a smart client and the OpenNetCF framework. All of that would tempt you to start freaking out completetly. In the keynote was a nice quote on that:

    • Two industries who call their clients “users” are the IT guys and the drug dealers. The first rule of being a drug dealer is ”Don’t get high on your own supply” an IT guys rule should be similar and they should write the code that makes the game, not waste their time in someone else’s GUI.

    I don't know who really said that, I don't think the speaker had invented it himself, and Google did not bring me any further. Anyone ?

    Another noteworthy thing was the presentation of Sander “devtips” Gerz on programming for the tablet PC. Visited by almost 50 developers (on a total of ~300). There were quite a number of tablets around. I brought my own to check me email using the hotspot. And Ginny Caughey did a presentation on creating mobile apps in Visual Studio. To operate the stylus of the emulated Pocket PC she used the pen of her tablet. Which adds a lot to the realism of the emulation.

    Just read that Teun was there to.

    Peter

  • Viewstate (hog) and the datagrid

    Sometime ago I had been wrestling through the viewstate and blogged on it. On a page with a datagrid the viewstate can be enormous. As the viewstate travels over the wire on every roundtrip this can be quite a problem in a situation where the bandwidth is limited. A lot of data in a datagrid is reread on every roundtrip, having it also in the viewstate is quite a waste. But some of the properties of a datagrid, like the selectedindex have to be preserved over the roundtrips. The viewstate can be disabled on a control basis. Which will also disable the viewstate of all controls owned by the control. Disabling it on a datagrid will also disable it for the controls in a template column. Disabling it on the page will disable it for all controls on the page.

    The problem with the viewstate of the datagrid is that you need it for some integers and end up with one which stores an entire grid. In a comment on the old post Simon asks if there is an easy way out of this. Something like the Whideby solution where you can disable the viewstate but preserve the main properties like SelectedIndex. There is, it takes some lines of code.

    Disable the viewstate of  the datagrid (and other controls), but do not disable the viewstate of the page itself. You use the latter to save your properties over roundtrips. Something like this :

    const string mySelIndex = "MySelIndex";
    private int mySelectedIndex
    {
       get
       {
          if (this.ViewState[mySelIndex] == null)
             return -1;
          else
             return (int)this.ViewState[mySelIndex];
       }
       set
      {
          this.ViewState[mySelIndex] = value;
       }
    }

    ...

    private void Page_Load(object sender, System.EventArgs e)
    {
       // Read data here
       DataGrid1.DataBind();
       DataGrid1.SelectedIndex = this.mySelectedIndex;
    }

    private void WebForm1_PreRender(object sender, System.EventArgs e)
    {
       this.mySelectedIndex = DataGrid1.SelectedIndex;
    }

    The page has a new private property mySelectedInded. Which uses the viewstate of the page itself to store the index. In the page load the index is read, in the page prerender it is saved. The page still does have a viewstate but you will see that it is very very small. Get the idea ?

    Peter

    Posted Dec 15 2004, 01:25 PM by pvanooijen with no comments
    Filed under:
  • Recognizing handwritten text on a tablet PC

    Way back on primary school (1963) my teacher tried to learn me to write. First with a pencil, later with a pen. It never was a big success, over the years I always had insufficient marks and nobody (including myself) could usually read what I had written down. Which made me a very early adopter for typewriters and later PC's with word-processors. Now, many years, cool keyboards and monster mice later I'm returning to the pen. That is, the tablet PC pen. Writing with a pen is far more comfortable and is a relief when your hands and wrists are sore of typing. And the tablet PC's handwriting does something most human had given up on: it does understand what I try to write down.

    Handwriting recognition is integrated in every corner of the OS but imho it is only implemented right in one place: in the text input panel. While you scribble the input panel shows the recognition results in the tooltips. This is a tremendous feedback. When you seen something is not recognized as the intended word you can correct it on the fly in the scribbling. No need to erase anything, just scribble over the letters misunderstood. Just like you would do with pen and paper.

    When you do a text recognition in a tool like Windows Journal an all text dialog will pop up and there is no longer the possibility to pen-correct your scribbling. I find that far less productive.

    The basics of text recognition on the fly is not that difficult. to implement in your own tablet apps. The ink in a tablet is modeled in a collection of Stroke objects. An ink aware control has an Ink property which has a Strokes collection. The Strokes collection has an overriden ToString method which will recognize the strokes. (See this article for an introduction to the Tablet API).  When a stroke is added the control fires an OnStroke event. In the eventhandler you can do the recognition and present the result.

    This demo application has an Inkpicture control and a label. The onStroke event is a one-liner.

    private void inkPicture1_Stroke(object sender, Microsoft.Ink.InkCollectorStrokeEventArgs e)
    {
       label1.Text = inkPicture1.Ink.Strokes.ToString();
    }

    Now this app has the basic feedback functionality.

    Text recognition is expensive. What you will see is that the writing will lag behind as the text starts exceeding something like 10 words. After that you have to accept the recognized text and clear the picture or start using a more sophisticated algorithm.

    Peter

  • Tablet PC : What can and what cannot be overlaid with an InkOverlay object

    Part of the tablet PC API is the Inkoverlay class. The constructor takes a control or even a windows handle. The user can scrible on the associated window. You can pass almost any handle to the constructor, like the handle of an ActiveX control on your Winform. This snippet makes the calender ActiveX a pen target:

    private InkOverlay io;

    io = new InkOverlay(axCalendar1.Handle);
    io.AttachMode = InkOverlayAttachMode.InFront;
    io.Enabled = true;

    Now the user can scrible over the calender ActiveX control.

    The control itself can no longer be clicked as it is shielded off by the ink-overlay.

    There is one limitation to the handles accepted, they have to be owned by the same process. Passing a handle to (the mainform of) another application will result in an exception. Which is a pitty, else making a general annotation app for a tablet would have been very easy. It would be a matter of covering the app with an Inkoverlay object.

    Peter

  • VS live and tablet development

    Just registered for the coming VS live conference in San Fransisco. My main reason to go is the emphasis on tablet development. The conference is actually a combination of several conferences, including Microsoft Windows Anywhere. There is a tablet track, a tablet pre-conference and a post-conference session. 4 solid days. Going to be great.

    Peter

  • Winning apps think in ink

    Those of you who visited the 2003 PDC propably remember the slogan “Does your code think in ink ?” It was a contest for cool tablet PC apps. Finaly a winner is declared, PC magazine has published a good overview of the top tablet apps. If you have a tablet do check out the winning ArtRage, an app which redifines making sketches with a computer and is freeware ! If you don't have a tablet, get a tablet first, enjoy its .net development possibilities and get Artrage !

    Peter

  • How to find out which control was responsible for the postback of an ASP.NET web form

    This sounds and is so trivial that it is well hidden in the docs.

    On my form is a datalist with in each row a label and a radiobuttonlist. On the radiobuttonlist autopostback is set to true, selecting another radiobutton will lead to a roundtrip. The items of a datalist are templates so there are no codebehind eventhandler for the controls. But my code needs to know which row of the datalist triggered the postback. This is a part of the HTML rendered:

    <span id="DataList1__ctl11_Label1" style="height:1px;width:336px;">Wijzigingen in het suiker en specialiteiten gebouw, hygiënische ruimten of installaties voor opslag van produktspan>
    <span id="DataList1__ctl11_RadioButtonListAntwoord" style="height:5px;width:142px;"><input id="DataList1__ctl11_RadioButtonListAntwoord_0" type="radio" name="DataList1:_ctl11:RadioButtonListAntwoord" value="1" onclick="__doPostBack('DataList1__ctl11_RadioButtonListAntwoord_0','')" language="javascript" />

    <label for="DataList1__ctl11_RadioButtonListAntwoord_0">Jalabel><input id="DataList1__ctl11_RadioButtonListAntwoord_1" type="radio" name="DataList1:_ctl11:RadioButtonListAntwoord" value="2" onclick="__doPostBack('DataList1__ctl11_RadioButtonListAntwoord_1','')" language="javascript" />

    <label for="DataList1__ctl11_RadioButtonListAntwoord_1">Neelabel><input id="DataList1__ctl11_RadioButtonListAntwoord_2" type="radio" name="DataList1:_ctl11:RadioButtonListAntwoord" value="3" onclick="__doPostBack('DataList1__ctl11_RadioButtonListAntwoord_2','')" language="javascript" /><label for="DataList1__ctl11_RadioButtonListAntwoord_2">?label>span>
          

    Every radiobutton has a snippet of script which takes the control's ID as a parameter. The script function invoked is also in the HTML, it is the __doPostBack function found in every asp.net webform

    function __doPostBack(eventTarget, eventArgument) {
    		var theform;
    		if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) {
    			theform = document.forms["ProjektWegwijzer"];
    		}
    		else {
    			theform = document.ProjektWegwijzer;
    		}
    		theform.__EVENTTARGET.value = eventTarget.split("$").join(":");
    		theform.__EVENTARGUMENT.value = eventArgument;
    		theform.submit();
    	}

    It copies the (cleaned) name of the control into a form member. The contents of this form member can be read in the code behind.

    char[] splitters = {'_'};
    string[] pbCtrl = Request.Form["__EVENTTARGET"].Split(splitters);
    // Index of control ID's is 1-based !
    int lIndex = int.Parse(pbCtrl[2].Substring(3)) - 1;
    int aw = int.Parse(pbCtrl[4]);

    The ID of all the radibuttons have a format like DataList1__ctlxx_RadioButtonListAntwoord_y. In it xx will return the datalist row which triggered the callback and yy the index of the radiobutton.

    Peter

More Posts

Our Sponsors

Free Tech Publications

This Blog

Syndication

News