Thursday, June 05, 2008
Wow, someone has been busy. There just appeared 46 brand new AJAX Control Toolkit tutorials. They're nice and short to show specific topics and needs. Nicely done.

Grz, Kris.

Thursday, June 05, 2008 7:48:59 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Wednesday, December 19, 2007
Just received this by email from my collegue Jean-Christophe at my current client BICS. Apparently one of my MVP colleagues set up a wiki for LINQ related technology. If you want to take a look at it you can navigate to Hooked on LINQ.

This is a nice addition to my earlier post: 101 LINQ to SQL samples. I guess we all know what to do during the coming holidays...

Grz, Kris.
 |  |  | 
Wednesday, December 19, 2007 9:01:35 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, November 19, 2007

on

Lots to learn, not enough free time unfortunately.

Grz, Kris.

Monday, November 19, 2007 8:18:22 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Sunday, September 09, 2007

Standard out of the box ASP.NET 2.0 uses SQL Server Express for the Application Services (Membership, Roles, ...). However sometimes you don't want it to be like that because you don't want to pay extra for SQL Server to your hosting company. In the past you practically had to rewrite your application or at least the Data Access Layer to be able to use an alternative database. Thanks to the Provider model that's being used by ASP.NET 2.0 it's possible to develop an application while another team could create an alternative provider and afterwards use some configuration to let your application make use of this new provider.

So, when you're reading this, it means you're interested in changing your default SQL Server based applications services to Access. First of all make sure that you download the Sample Access Providers provided by Microsoft.
This is a .vsi file and you could run it to get installed. But rather then doing that, you simply rename the extension from vsi to zip. That's right, you simply rename it and use a zip utitlity, like the built in zip functionality of Windows to extract the files.

accessproviders01 
Figure 1: the unpacked Sample Access Providers

These are the files I got after extracting the .zip file. You see there's already a full blown ASPNetDB.mdb file in it that has the needed tables and queries to be able to support  the Application Services. Figure 2 shows what's already available. As you can see

accessproviders03
Figure 2: Overview of the available tables and queries in the accompanied Access database file.

After extracting the files we still need to compile the source code in order to be able to integrate the providers into our web application. If you have Visual Studio or Visual C# Express installed you open your IDE of choice. You navigate to the menu and click File, Open, Project/Solution. Once the dialog opens you navigate to where you extracted the contents of the zip file. Select the Access.csproj, see Figure 1, and click the Open button.

Once opened you can see the following in the solution (Figure 3). Now you just have to build the solution, preferably in Release mode.

accessproviders04
Figure 3: solution

Ok, the output of building the solution provides us with an assembly named SampleAccessProviders.dll. To find it back you just need to open a windows explorer and navigate to the place where you extracted the zip file to. There you should see a newly created subfolder called bin and in that one that's called Release. In the Release folder you'll find the built assembly.

Now that we have created the assembly it's time to actually use it. Open your Visual Studio or Visual Web Developer Express and create a new website. In the project you create a new subfolder called bin. After creation right click on it and choose Add existing item... from the context menu that appears. Navigate to the place where the built assembly is. Add it to the bin folder of the website project. After that repeat the same thing with the access database (ASPNetDB.mdb) file but this time put it in the dedicated folder App_Data which is one of the predefined ASP.NET 2.0 subfolders.

Open the web.config file of the website project. You'll need to make some adjustments here in order to be able to use it Access provider. When you take a look at figure 1 you'll see that the extracted zip file also contains a web.config. It already contains the needed parts so the only thing required is just to copy paste the needed configuration parts.
First of all the connectionstring to the access database:

    <connectionStrings>
        <add name="AccessFileName" connectionString="~/App_Data/ASPNetDB.mdb" providerName="System.Data.OleDb"/>
    </connectionStrings>

 Also be sure to change the authentication mode which defaults to Windows. Make it use Forms instead like this:

<authentication mode="Forms">
  <forms loginUrl="mylogin.aspx" defaultUrl="Login.aspx"/>
</authentication>

After that you can simply copy in the providers that you need. In this tutorial I'll only copy in the Membership provider part:

<membership defaultProvider="AccessMembershipProvider">
    <providers>
        <clear/>
        <add name="AccessMembershipProvider" 
                type="Samples.AccessProviders.AccessMembershipProvider, SampleAccessProviders" 
            connectionStringName="AccessFileName" 
            enablePasswordRetrieval="false" 
            enablePasswordReset="false" 
            requiresUniqueEmail="false" 
            requiresQuestionAndAnswer="false" 
            minRequiredPasswordLength="1" 
            minRequiredNonalphanumericCharacters="0" 
            applicationName="SampleSite" 
            hashAlgorithmType="SHA1" 
            passwordFormat="Hashed"/>
    </providers>
</membership>

Other provider parts, like the Roles and Profile, are just as easily copied.

Just to see if things are working is quite easy. Just open the ASP.NET Configuration Tool. You do that by navigating to the menu and click Website, ASP.NET Configuration. A browser opens with the tool in place. Click the fourth tab (Provider). Select the second link ("Select a different provider for each feature (advanced)). There you'll see that the access provider is selected (figure 4)

accessproviders05
Figure 4: Provider tab in the ASP.NET Configuration Tool

In the membership configuration you notice the <clear/> tag. This clears all previous settings from a hierarchical higher configuration. If you remove that particlar line you'll see that you get another radiobutton option that lists the default AspNetSqlMembershipProvider. If you would select that option SQL Server's used again. 

Grz, Kris.

Sunday, September 09, 2007 8:25:12 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [1]  |  Trackback
 Saturday, July 21, 2007

Taken from the download site:

The Windows Server 2008 Developer Training Kit includes a set of hands-on-labs and presentations for technologies such as IIS7, Management, WCF, WF, Windows CardSpace, Windows PowerShell, Virtualization and the Transactional File System (TxF). The content was originally created by Microsoft's Developer & Platform Evangelism group as part of the Windows Server 2008 Touchdown training activities.
The seven hands-on labs included in this kit are based on the DinnerNow sample application.

Windows Server 2008 Developer Training Kit (Beta 3).

Grz, Kris.

Saturday, July 21, 2007 10:44:15 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, June 25, 2007

One of the nice things when you gather with a bunch of tech minded people like yourself (Microsoft VIP Community Offsite 2007) is that you get to know urls to interesting tech stuff. Apparently already very known, except by me are the MSDN UK nuggets. Some small, interesting videos that highlight a specific topic in 10-15 minutes. I sure do like the idea as most webcasts are too long or they want to cover as much as possible in an as short as possible time span with as endresult that nobody gets the message.

Another one that I found related to that, and one that seems very new so most of my tech savvy friends don't know about it untill when they read my blog is this Nibbles site. It seems to only have some tutorials at the moment, especially focussed on Blend and Silverlight/WPF. As I'm keen on learning both I'll sure be checking this one out.

Grz, Kris.

Monday, June 25, 2007 2:50:18 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Saturday, April 28, 2007

As a moderator on the ASP.NET I often see a request for a certain keyboard shortcut to do a specific thing. Since I like shortcuts myself and use them very often I wanted to provide a little how to here:

First you go to Tools | Customize and click the button Keyboard...

The following screen appears:

If you want to check out which shortcut corresponds to which command you can point the cursor to the textbox at 1. There you can type in the keyboard shortcut like ctrl + K, ctrl + D. In the dropdownlist at the bottom you can then see where the shortcut is used at that moment like in the following figure:

You can clearly see that the command in the Text editor, that's where you type your code, is the Edit.FormatDocument which outlines your code properly.

The other way around can also be done. If you type into 2 the command you're after, in my example Edit.FormatDocument you get to see which shortcut combination in the dropdownlist right underneath it (Shortcuts for selected command). If you're not satisfied with it you can then, in textbox 1, type in your own shortcut combination and click the Assign button.

If you want to fine grain where a certain keyboard combination is used you can select where to use it in the dropdownlist "Use new shortcut in".

Grz, Kris.

kick it on DotNetKicks.com

Saturday, April 28, 2007 11:44:52 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [1]  |  Trackback
 Saturday, March 03, 2007

Microsoft provides since recently a new learning center for the beginning developer. Totally dedicated to the freely available Expression editions of Visual Studio 2005 people who are interested in beginning to learn to program can take advantage of.

You can find the Learning Center here.

Another interesting piece of information are the SQL Server 2005 Express For Beginners screencasts.

Grz, Kris.

kick it on DotNetKicks.com

 

Saturday, March 03, 2007 9:50:15 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Thursday, January 04, 2007

Hi,

I always like to recommend these tutorials to people who are taking their first steps with ASP.NET 2.0. Since I have a couple days off I thought, why not take the lessons myself? The first tutorial shows how to use TableAdapters, which was something I never used before, so it also turned out to be very interesting for me too.

You can find the data tutorials here.

The next weekend and weeks I hope to spend some time on ASP.NET AJAX as well.

Grz, Kris.

Thursday, January 04, 2007 1:25:38 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, October 23, 2006

Setting the Width property of a control in ASP.NET is mostly done in the properties pane or by declaratively setting it in the markup. However sometimes you want to set it in code. This can be done by using the Unit structure.

I crafted some small example that you can run to play around with the different UnitType enumerations. Possible choises are:

Cm Measurement is in centimeters. 
Em Measurement is relative to the height of the parent element's font. 
Ex Measurement is relative to the height of the lowercase letter x of the parent element's font. 
Inch Measurement is in inches. 
Mm Measurement is in millimeters. 
Percentage Measurement is a percentage relative to the parent element. 
Pica Measurement is in picas. A pica represents 12 points. 
Pixel Measurement is in pixels. 
Point Measurement is in points. A point represents 1/72 of an inch. 

The sample provided here loops over the possible unit types and fills up the dropdownlist. The second textbox is used to fill in an amount to set the Width of the first textbox control to. If you don't fill in an amount it automatically defaults to 30.

    1 <%@ Page Language="C#" %>

    2 

    3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    4 

    5 <script runat="server">

    6 

    7     protected void Page_Load(object sender, EventArgs e)

    8     {

    9         if (!Page.IsPostBack)

   10         {

   11             // Set the original width to 300 pixels

   12             TextBox1.Width = new Unit(300);

   13 

   14             // Loop over the possible unit types

   15             foreach (string s in Enum.GetNames(typeof(UnitType)))

   16                 DropDownListSelectUnitType.Items.Add(Enum.Format(typeof(UnitType), Enum.Parse(typeof(UnitType), s), "G"));

   17         }

   18     }

   19 

   20     protected void Button1_Click(object sender, EventArgs e)

   21     {

   22         // Obtain the chosen width, if it's not filled it default to 30

   23         int width = !String.IsNullOrEmpty(TextBoxSetWidth.Text) ? Convert.ToInt32(TextBoxSetWidth.Text) : 30;

   24 

   25         // Obtain the chosen unit type

   26         UnitType type = (UnitType)Enum.Parse(typeof(UnitType), DropDownListSelectUnitType.SelectedItem.Text, true);

   27 

   28         // Use the Unit structure to set the width of the textbox

   29         TextBox1.Width = new Unit(width, type);

   30     }

   31 </script>

   32 

   33 <html xmlns="http://www.w3.org/1999/xhtml" >

   34 <head runat="server">

   35     <title>Untitled Page</title>

   36 </head>

   37 <body>

   38     <form id="form1" runat="server">

   39     <div>

   40         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />

   41         <br />

   42         <br />

   43         Width: <asp:TextBox ID="TextBoxSetWidth" runat="server" Width="40px"></asp:TextBox><br />

   44         Type: <asp:DropDownList ID="DropDownListSelectUnitType" runat="server">

   45         </asp:DropDownList><br />

   46         <asp:Button ID="Button1" runat="server" Text="Set Textboxes width" OnClick="Button1_Click" />

   47     </div>

   48     </form>

   49 </body>

   50 </html>

Grz, Kris.

Monday, October 23, 2006 10:05:53 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Tuesday, August 29, 2006

People that use ASP.NET know that it's very easy to use the Properties pane in visual studio to quickly set some properties on a server control. By default already a lot of such properties are made available but sometimes you just want something that just doesn't come out of the box. Luckely the WebControl class also provides the Attributes property which is of type AttributeCollection. You can use the Add method to add new attributes to your control.

To make it more clear I created a small demo page that I used to answer a question on the ASP.NET forums.

    1 <%@ Page Language="C#" %>

    2 

    3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    4 

    5 <script runat="server">

    6 

    7     protected void Page_Load(object sender, EventArgs e)

    8     {

    9         ListBox1.Attributes.Add("ondblclick", "GetValue();");

   10     }

   11 </script>

   12 

   13 <html xmlns="http://www.w3.org/1999/xhtml" >

   14 <head runat="server">

   15     <title>Untitled Page</title>

   16     <script type="text/ecmascript">

   17     function GetValue()

   18     {

   19         box = document.getElementById('ListBox1');

   20         x = box.options[box.selectedIndex].value;

   21 

   22         if(document.all)

   23             document.getElementById('Label1').innerText = x;

   24         else // FireFox doesn't implement the innerText property.

   25             document.getElementById('Label1').textContent = x; 

   26     }

   27     </script>

   28 </head>

   29 <body>

   30     <form id="form1" runat="server">

   31     <div>

   32         <asp:ListBox ID="ListBox1" runat="server">

   33             <asp:ListItem>One</asp:ListItem>

   34             <asp:ListItem>Two</asp:ListItem>

   35             <asp:ListItem>Three</asp:ListItem>

   36         </asp:ListBox></div>

   37         <asp:Label runat="server" ID="Label1" />

   38     </form>

   39 </body>

   40 </html>

On line 9 you can see that I add an attribute. In this case the ondblClick javascript event. This results, once rendered in a browser to have the ability to double click on an item and have the selected value set as being the text of the label control. The javascript function that accomplishes this task is on line 19 - 25.

Tuesday, August 29, 2006 6:21:02 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Friday, July 21, 2006

Most people that have even limited experience with ASP.NET know that you can set the properties of a server control quite easily in the Properties pane of vs.net. Once done this gets set declaratively in the attributes collection of the control. You can see this quite easily when you take a look at the markup of your webform. 

A little less known however is the fact that this also can be done with user controls. You can create a public property on the user control, place it on a webform and set, declaratively, the property in the markup of your webform.
I did it myself a couple of years ago when I crafted a user control that on a certain webform would show the entire list coming from a database and on another webform it should only let a subset of that list be seen. So using this technique I was able to set which list would be shown, from the webform. Keeping the webform in control of what's shown once it was rendered.

A small example is in place here:

First I have my user control:

    1 <%@ Control Language="C#" ClassName="PropertySetDeclaratively" %>

    2 

    3 <script runat="server">

    4 

    5     public string ShowValue

    6     {

    7         set { Label1.Text = value; }

    8     }

    9 

   10 </script>

   11 

   12 <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

As you can see, I created a public property ShowValue in which the Text of the Label control, Label1, will be set to the value that's passed to it.

And the webform which hosts the user control:

    1 <%@ Page Language="C#" %>

    2 

    3 <%@ Register Src="PropertySetDeclaratively.ascx" TagName="PropertySetDeclaratively"

    4     TagPrefix="uc1" %>

    5 

    6 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

    7     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    8 

    9 <script runat="server">

   10 

   11 </script>

   12 

   13 <html xmlns="http://www.w3.org/1999/xhtml" >

   14 <head runat="server">

   15     <title>Untitled Page</title>

   16 </head>

   17 <body>

   18     <form id="form1" runat="server">

   19     <div>

   20         <uc1:PropertySetDeclaratively ID="PropertySetDeclaratively1" runat="server" ShowValue="13" />

   21     </div>

   22     </form>

   23 </body>

   24 </html>

In the syntax on line 20 you see that the ShowValue, the public property on the user control, is set to 13. Once rendered the Label will be filled up with the passed content. Also be aware that the declaratively set property is filled up even before the OnInit event of the user control gets handled.

As a nice side effect we can also turn off ViewState for the Label control because it gets set automatically on each page call, be it either an initial request or a postback. You turn of Viewstate of a control by setting its EnableViewState property to false.

Grz, Kris.

Friday, July 21, 2006 6:39:14 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Friday, July 07, 2006

dasBlog is a decent blogging engine originally created by Clemens Vasters. A nice thing that not many people seem to be aware of is that you can easily extend it by creating custom macros. Such a custom macro isn't anything else than just a class library that you can hook into your copy of dasBlog and use it later on in one of the available templates that make up the website.

I couldn't really find a lot of information about this, so I decided to create my own article about the subject that also puts in the solutions I found. 
Also I would like to show the code that I use in my current installment that's reusable directly for other dasBlog users.

Creation:

So, as I already mentioned, creating macros is just like creating a class library. So lets fire up vs.net, create a new project and in the templates choose Class library like in Figure 1. The name of the project is also important when we will be configuring dasBlog to let it know about the existence of our macros. I chose MydasBlogMacros but you can choose your own name of course.


Figure 1: Create a new project based upon the Class Library template.

If you haven't downloaded the code for dasBlog now's a good time to do so. You can download the bits from the official site(1) or you can use the guideline to get the latest bits and pieces(2) like I did.

Now we have to add 3 references in order to be able to create our custom macro. You do this by right clicking in the Solution Explorer of Visual Studio.NET on the References node. Take a look at Figure 2 to choose System.Web, and Figure 3 to choose 2 assemblies that are from dasBlog itself. These 2 are newTelligence.DasBlog.Runtime and newTelligence.DasBlog.Web.Core. The result is shown in Figure 4.


Figure 2: locate and choose System.Web


Figure 3: Navigate to the bin folder of the compiled bits of dasBlog and select the needed assemblies.


Figure 4: After adding the needed references.

In Figure 4 you can also see that I deleted the default Class1.cs file and added a new class with the name Macros.cs. This is the only class we'll need for the moment. Here's the code for the Macros class:

    1 using System;

    2 using System.Collections.Generic;

    3 using System.Text;

    4 using System.Web.UI;

    5 using newtelligence.DasBlog.Runtime;

    6 using newtelligence.DasBlog.Web.Core;

    7 

    8 namespace MydasBlogMacros

    9 {

   10     public class MyMacros

   11     {

   12         protected SharedBasePage sharedBasePage;

   13         protected Entry currentEntry;

   14 

   15         public MyMacros(SharedBasePage page, Entry entry)

   16         {

   17             sharedBasePage = page;

   18             currentEntry = entry;

   19         }

   20 

   21         public virtual Control EmailIt(string linkText, string cssStyle)

   22         {

   23             if (this.currentEntry != null)

   24             {

   25                 string link = this.currentEntry.Link != null

   26                     ? this.currentEntry.Link : Utils.GetPermaLinkUrl(this.currentEntry);

   27 

   28                 return new LiteralControl("<a href=\"mailto:?subject=" + this.currentEntry.Title +

   29                     "&body=I found this to be a great read: " + link +

   30                     ". Hope you like it too.\" class=\"" +

   31                     cssStyle + "\">" + linkText + "</a>");

   32             }

   33 

   34             return new LiteralControl("");

   35         }

   36 

   37         public virtual Control Delicious(string linkText, string cssStyle)

   38         {

   39             if (this.currentEntry != null)

   40             {

   41                 string link = this.currentEntry.Link != null

   42                     ? this.currentEntry.Link : Utils.GetPermaLinkUrl(this.currentEntry);

   43 

   44                 return new LiteralControl("<a href=\"http://del.icio.us/post?url=" + link

   45                     +  "&title=" + this.currentEntry.Title + "\" class=\"" + cssStyle + "\">"

   46                     + linkText + "</a>");

   47             }

   48 

   49             return new LiteralControl("");

   50         }

   51 

   52         public virtual Control Digg(string linkText, string cssStyle)

   53         {

   54             string link = this.currentEntry.Link != null

   55                     ? this.currentEntry.Link : Utils.GetPermaLinkUrl(this.currentEntry);

   56 

   57             return new LiteralControl("<a href=\"http://www.digg.com/submit?url=" + link +

   58                 "\" class=\"" + cssStyle + "\">"

   59                 + linkText + "</a>");

   60         }

   61 

   62         public virtual Control Technorati(string linkText, string cssStyle)

   63         {

   64             if (this.currentEntry != null)

   65             {

   66                 string link = this.currentEntry.Link != null

   67                     ? this.currentEntry.Link : Utils.GetPermaLinkUrl(this.currentEntry);

   68 

   69                 return new LiteralControl("<a href=\"http://www.technorati.com/search/" +

   70                     this.currentEntry.Title +

   71                     "\" class=\"" + cssStyle + "\">"

   72                     + linkText + "</a>");

   73             }

   74 

   75             return new LiteralControl("");

   76         }

   77     }

   78 }

Note that the signature in the constructor is required in order to let the macros work!
Besides the constructor I created 4 methods, which will be the macros eventually, the first one EmailIt is for creating a link with the url of the current item in the body so someone can easily mail it to someone whom (s)he thinks will also be interested in the article. The other 3 are for well known web 2.0 services: del.icio.us, digg and technorati.

The methods/macros take all 2 input parameters: the string to appear in the link and the css style that will go in the class attribute of the rendered tag. Separating content and layout has several benefits: it's easy to update in a single place and an external .css file can be cached on the client.

After compiling the source code, preferably in Release mode, and after that open windows explorer and navigate to where the .dll file is created. By default this will be the place where you created your project and in there the subfolders /bin/Release. Now copy the .dll file to the /bin subfolder of the dasBlog solution (this is the same folder where you got your references from).

Configure dasBlog:

We created our macros assembly, dropped it in the /bin folder of the dasBlog folder, but we still need to configure dasBlog in such a way that it knows of the existance of our macros. This is entirely done in the web.config file that can be found in the root folder of dasBlog. Open it with your favorite IDE and uncomment the following line at the top of the web.config:

<section name="newtelligence.DasBlog.Macros" type="newtelligence.DasBlog.Web.Core.MacroSectionHandler, newtelligence.DasBlog.Web.Core" />

Now navigate to the tag <newtelligence.DasBlog.Macros>, uncomment it and add this line: