Archives

Archives / 2006 / April
  • [Books] Professional ASP.NET 2.0? Naaaah...

    Every now and then I like to read literature related to coding, design, refactoring and various development methodologies, especially when I know there's something new out there that I haven't been able to work with or look at yet.

    This time I thought I'll get myself a really fat and heavy book on ASP.NET 2.0 which digs into the changes between 1.1 and 2.0 and some tips on how to best use the goodies like new controls, membership, web parts and so on. Without doing too much investigation, I used the Internet book-shop I usually use and did a search on "ASP.NET 2.0". I got a number of hits and selected "Professional ASP.NET 2.0" from Wrox. The book is supposed to help "experienced developers make the transition to ASP.NET 2.0".

    I should have read some reviews I guess... it was kind of a bad buy it seems. 1258 pages (!) and the book doesn't even bring up how to hide menu items based on a web.sitemap file by editing the sitemap provider section in web.config. Something this great video on the MS ASP.NET Developer Center shows. One reason the book is so thick is probably because each code sample is in both VB.NET and C# and you also get page after page with class properties. I dunno, but Wrox got a separate ASP.NET 2.0 book on security, roles and stuff, maybe they brought it up there. I may have had bad luck with the sitemap provider thing I was looking for, but there were other things I needed that were missing as well. I can't say I've looked at ALL thousand or more pages, but...

    EDIT: Gah... Page 86 in the book describes how you can use precompile.axd to precompile the website. Well, that function was removed after beta 1 as far as I know. Not very impressive...

    The book do have some samples around client-side callbacks which were good, but overall I wouldn't recommend it.

  • [.NET 2.0] How to get Selected-events from an ASP.NET 2.0 TreeView Control using a Web.SiteMap File

    The new ASP.NET 2.0 TreeView control looks neat, and it's very simple to use in conjunction with a web.sitemap file. I spent some time on it yesterday but there were a few things the TreeView control and I never could agree on. For example, when using a TreeView Control in conjunction with a .sitemap file (via the SiteMapDataSource), you cannot get any selection events to fire at all because the treeview is in navigation mode.

    Good news is that it is not impossible to work around it, but it took me a while to figure out, and not without some serious help from Google... The trick is to get the TreeView in selection mode instead of navigation mode. For that to happen, the NavigateUrl property for the node has to be an empty string (""). So, what you have to do is to manually edit the TreeNode DataBindings of the TreeView control and add som code to control the redirection to the right page or else you will stay on the same page forever :)

    From start:

    1. Create your web.sitemap file
    2. Optionally - create your master-page where you want your treeview and breadcrumb controls to sit
    3. Drag/drop a TreeView Control onto the page
    4. Set the ExpandDepth to whatever depth you like 
    5. Choose a new datasource and select a Site Map (the control should now display your nodes from the web.sitemap file)
    6. Select to Edit TreeNode DataBindings
    7. Mark the SiteMapNode from the list of available data bidings and Add it as a selected data binding
    8. Uncheck the Auto-generate data bindings checkbox, we don't need it
    9. Edit the SiteMapNode properties:
      1. Set the TextField to 'Title'
      2. Set the ValueField to 'Url'
      3. Optionally - set any default parameters you like
    10. Finally, add the SelectedNodeChanged event for the TreeView Control and some code in that event to redirect to the right page:

    protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)

    {

        Response.Redirect(TreeView1.SelectedNode.Value, "false");

    }

    This is a sample of how the TreeView code in the ASPX page could look like:

    <asp:TreeView ID="TreeView1" runat="server" AutoGenerateDataBindings="False" DataSourceID="SiteMapDataSource1"

        PopulateNodesFromClient="False" ImageSet="WindowsHelp" OnSelectedNodeChanged="TreeView1_SelectedNodeChanged">

        <DataBindings>

            <asp:TreeNodeBinding DataMember="SiteMapNode" TextField="Title" ValueField="Url" />

        </DataBindings>

        <ParentNodeStyle Font-Bold="False" />

        <HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />

        <SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False" HorizontalPadding="0px"

            VerticalPadding="0px" />

        <NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px"

            NodeSpacing="0px" VerticalPadding="1px" />

    </asp:TreeView>

     

    Now if you try out your web site, the SelectedModeChanged event should fire. One big drawback with this piece of code is that now the treeview fires a PostBack event and you have to add the extra Response.Redirect() to get to the right page. Without the redirect the treeview won't be able to automatically detect which page you're on and render the treeview accordingly.

    If you want to add a breadcrumb (SiteMapPath) to the page, just drag/drop it in there. It works out of the box.

  • [.NET 2.0] Membership and Personalization Provider for Access Database

    Not sure why vs2005 didn't ship with providers for Access databases, but Access is quite useful if you want to develop small and simple websites and do not have access to SQL Server or similar. I run a small website hosted by an ISP and even though they support ASP.NET 2.0, I don't have access to SQL Server.

    A sample Access provider is available for download on the MSDN ASP.NET Developer Center section with Provider Toolkit information. I've tried it, and it seems to work good enough for my needs. I'm having some troubles writing to the database under IIS on Windows 2000, even if I set all the security and permission stuff as it should be. Well, as long as it works under Cassini and on my website I don't care :)

    EDIT: Stupid me, even though I had set access rights and permissions on all folders down to APP_DATA, the MDB-files still had the old permissions set on them. I explicitly gave the ASPNET user write access to the file and now it works like a charm :)

  • Virtual Server 2005 R2 Enterprise Edition for Free

    If you by chance missed it - look here for details.Snip from the download page:

    The full software for 32-bit and 64-bit versions is available as a free download. Register to pre-order a CD (available May 2006) or to download the full software.

    Go get it already :)