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

Peter's Gekko

public Blog MyNotepad : Imho { }

June 2004 - Posts

  • Liars, big liars and blog statistics

    Just like everybody else in this bussiness I am sensitive to numbers and even more to statistics. At this moment my blog reads 198 posts, 499 comments and 70 trackbacks. The next post, number 200, has to be something special. The next comment as well. But I'm not sure about the third statistic, the number of trackbacks. It is supposed to count the number of times a referal to your blog is posted. Which is hard to follow. When I refer to my neighbours blog his trackback count does not increase, when he refers to mine my number does increase. When I refer to one of my own posts, like my first blog post my number does increase. Some days the trackback count rises fast, other weeks it does not change at all. In other words, the number of trackbacks does imho not stand for anything substantial. The number of views (only visible in the admin section) is far more informative.

    A lot of blogs don't display a trackback count at all. Ask me no questions and I'll tell you no lies.

    Peter

  • Adding eventhandlers at run time

    Having published a dnj article on events in asp.net I got presented with the following problem :

    The webform has an emty label and an empty table. At runtime the table is populated with a collection of imagebuttons. Every imagebutton will get an eventhandler.

    private void buildTable(int rows, int cols)
    {
       for (int
    i =0; i < rows; i++)
       {
             TableRow tr = new
    TableRow();
             for (int
    j = 0; j < cols; j++)
             {
                TableCell tc = new
    TableCell();
                ImageButton ib = new
    ImageButton();
                ib.ToolTip = string.Format("This is button {0} {1}"
    , i, j);
                ib.Click+=new
    ImageClickEventHandler(ib_Click);
                tc.Controls.Add(ib);
                tr.Cells.Add(tc);
             }
          Table1.Rows.Add(tr);
       }
    }

    The method is quite straigthforward. It creates table rows, table cells and adds an imagebutton to every cell. The same eventhandler is used for all buttons

    private void ib_Click(object sender, ImageClickEventArgs e)
    {
       ImageButton ib = sender as ImageButton;
       Label1.Text = string.Format("ToolTip: {0} X : {1} Y : {2}", ib.ToolTip, e.X, e.Y);
    }

    Running the code the label will display which button was clicked. For the details you are invited to the original article.

    The important part is the moment in the page life cycle the eventhandler is assigned. If the buildTable method is called from the page_load the event handler will work. If it is called in the pre-render the table will be populated but the eventhandlers will not fire. At that moment in the page life cycle the wire-up of events is allready set and fixed.

    Peter

     

  • Never name your table "project"

    I was working on two project management apps. For the same customer. In both apps I named the main table project. Dumb !!! Now the two apps are merging. The two project tables represent two different views on a (part of a) project. The code still works, namespaces and databases have to point out which view on a project I'm dealing with. But sometimes it's quite confusing. Lesson learned : “Don't give your tables general names”. Should be an open door :>

    Peter

  • Smart navigation : view source / save as in IE does not do what you expect it to do.

    Here's another quirck in smart naviagation.

    I have an aspx page with a lot of optional panels. In the prerender event the visibilty of the panels is set. This way I have the functionality of a multiple tabbed page. A radiobuttonlist makes up the tab-index, the panels are the tab-pages. Works great.

    Things get weird when I want to check the html emitted via Save/as or view source in IE. When smartnavigation is set to true IE will always return the HTML as it was on the first roundtrip. In my case the initial tab. Disabling smartnav or setting another initial tab does produce the html I was looking for.

    Peter

  • ASP.NET not working ? Flame you firewall !

    Some time ago I blogged how I got my broken asp.net working again. Which turned out to be a popular problem. My solution did not work for everybody, but the post became a place to discuss alternative solutions. The post should become a wiki, for the moment I'll recap a pattern (best described here):

    ASP.NET does not work well with (some) software firewalls. My XP sp1 is no problem, according to several sources ZoneAlarm is. If yor asp.net does not work and you do have a firewall try disabling the latter.

    Peter

  • VB (.NET) or C# ? No need to choose

    Dan Appleman has published a very neat article on VB.NET and C#. It's not about which one is a better language, which is a non-issue, but does show how to mix the best of both. Using the visual basic namespace in a piece of C# you can use the VB financial functions in your C# code.

    <quote>

    using Microsoft.VisualBasic;
    ........
    Console.Write("Your payment is: ");
    Console.WriteLine(Financial.Pmt(.05/12,    30*12,100000,0,  DueDate.BegOfPeriod).ToString("$0.00")) ;
    </quote>

    That's what .net is about.

    Peter

  • DotNed Showtime

    TechEd will be in Amsterdam. As a spin-off some good speakers will do a show for the Dutch dotned user group. Monday june 28th, Juval Lowy and Ingo Rammer will give a presentation in Purmerend. Register here, it's free !

    June the 30th the asp.net roadshow will hit the local MS office. The list of presentations looks quite good. Who will do them is not clear. Another TecEd passer by ? I'm not sure, the same (?) event is also on june the 21st.

    Peter

  • Security hits back again.

    Securing your machine and code may be good but does have its drawbacks. Recently I questioned anti virus software. Here's another little horror story. A new version of the Zonealarm firewall knocking out local asp.net.

    Peter

  • Merging webapps. Moving (typed) Crystal reports from one application to another.

    Two of my projects got so entangled that the only way out was merging them into one. They were several asp.net apps which had (code) references to each other. Two of them refering each other made the situation unworkable. Building the setup packages resulted in one working or the other working, depending which package I built first. When creating a setup package vs first builds all the projects in the package. When an assembly is refered it will be rebuilt and included. When an assembly is included in more than one package it is rebuild more than once. Leading to versioning hell.

    I created a new web app and created some folders in it (from the VS solution explorer !) To these folders I added the content and code from the former apps. Works like a snap. Except for my (what else ?) Crystal reports. 90% of the conversion time was spent on getting these to work. This time the process was interesting.

    Including the report “as is” leads to a succesfull build but an enigmatic error message at runtime:

    Unable to find the report in the manifest resources

    My apps use strong typed reports and reportdocuments from the component palette

    Several observations

    • A report looks like a rpt file. Behind the scenes is a (generated) cs file
    • This cs file is generated when you save the report design. See the custom tool in the proprties of a report.
    • That code is generated in the namespace of the application.
    • The reportdocument is refred in the namespace of the page hosting it

    The combination of the last two results in the error. To get things working took me these steps.

    1. Include the reports in the project
    2. Open the designer and save (to regenerate the report code)
    3. Make sure the pages on which the report is used are in the default namespace of the application
    4. Do not use reportdocuments

    Step 3 is easier in C# then VB. Here you see the namespace in the code behind. Changing the name will have the desired effect. To get an overview of the namespaces in your app use the class viewer.

    Too much of the reportdocument component is hard coded. Creating the report on the fly works just as well.

    private MotivatieRaport mv = new MotivatieRaport();
    dataSetProjektTonen.Merge(Projekt.ToonBaarProjekt(id));
    mv.SetDataSource(dataSetProjektTonen);
    CrystalReportViewer1.ReportSource = mv;

    The only extra line is the first one.

    Peter

     

  • Use an usercontrol in another application

    I'm wild about usercontrols, aka ascx'es. Very very usefull. But they do have one drawback : you cannot use a usercontrol in another application. Asp.net will tell you (at runtime) “this cannot be allowed”. Because it contains markup ? Pitty.

    Peter

  • Extreme programming adventures in C#

    At the moment I'm trying to read this book. Most reviews were good. To be honest I have great difficulties trying to get through. It is my first book on XP, I had hoped it would materialize extreme programming in some kind of way. But it does not. Yes you need a good story told by an experienced user and an experienced programmer. That should be kicking in an open door. And so far the adventures don't add much to that.

    You cannot teach experience, experience can only be gained by doing something. You can teach the big lines you see being experienced. You can teach about the tools to help you. And there is more out there than just the Nunit the book comes up with.

    But I'll ty to finish it.

    Peter

     

  • Does anti virus software make sense ?

    To start with a provacative answer : I don't think it does on the client. Two recent horror stories:

    • Norton anti virus is notorious. I've been doing a lot with COM, a major part of FAQ lists and support was dealing with nav disrupting automation functionality. This weekend I receievd an email from someone appologizing for not having replied before. Norton had been blocking all of his outgoing mail for over a week.
    • Someone else had made big investments in virus protection. Installed a lot of software and set up update subscriptions. Monday morning in his office. He switches on his computer, checks his mail, checks for virus-updates.... Bang.... Virus.

    The second is imho the keypoint why it makes no sense to have client side virus protection. Your mail provider should do the check. And most of them do. But the time gap between a new virus and an update of the profile at the provider is long enough for a virus to get through. If a big provider, whose is on the allert 24 hours a day, can't even catch all (and I don't blame them), how do you expect to keep up ?

    The only thing that does help is a good procedure. The user (and all his employees !) in the second case should have checked for the virus update before checking his mail. I use this procedure

    1. Never click an unknown attachment
    2. Make sure your machines have an IP address which is by definition unreachable. (192.168.x.x)

    I have no virus scanner and neither me or my wife or my kids have (so far) been infected. I even challenge you to try to get through :>

    Peter

     

  • Apress authors are blogging

    Apress authors have started blogging to. Makes a good stylish read. These people just love to write.

    Peter

More Posts