# Tuesday, 04 March 2014

On a regular basis Microsoft brings out cool and easy to follow tutorials. I just noticed that the ones about Entity Framework and ASP.NET MVC got updated.

For Entity Framework the following new things in version 6 are handled:

  • Connection resiliency
  • Command interception
  • Code-based configuration
  • Async
  • Stored procedures

9 tutorials were refurbished:

And 3 new tutorials were created:

For people who’re still on older versions don’t despair, they’re still available under http://www.asp.net/mvc/tutorials/getting-started-with-ef-5-using-mvc-4

Grz, Kris.

Tuesday, 04 March 2014 12:08:00 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Wednesday, 10 August 2011

When I look outside I see quite some clouds passing by. Not what you want during summer, especially when rain starts. However there are also fun clouds. They are colored in Azure. Microsoft Belgium provides a new summer course for us: Dive into the Windows Azure platform this summer.

I also blogged about other courses you could take a look at:

Have fun diving into the cool stuff!

ff718229_header

Grz, Kris.

Azure | Belgium | Course | Microsoft | MSDN | Tutorial
Wednesday, 10 August 2011 10:48:38 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Wednesday, 03 August 2011

A couple of weeks ago you could already find yourself getting knowledge about Windows Phone 7 Mango and Visual Studio 2010 ALM.

Because there’s always more to learn Microsoft put a new summer course online: Dive into HTML 5 this summer. Cool and refreshing, so what are you waiting for to get your feet wet. Happy diving!

html5

ff718229_header

Grz, Kris.

Belgium | Course | HTML5 | Microsoft | MSDN | Tutorial
Wednesday, 03 August 2011 13:53:29 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Friday, 22 July 2011

Either you’re melting away like an ice cream put in the oven or you’re being washed away by rains but there’s one certainty since last summer: There are several dive in courses from Microsoft to keep you nice and comfortable in front of your pc trying out new stuff and enjoying updates on technologies.

This year Microsoft Belgium has foreseen 2 courses for us:

Take a dive like this person already did:

ff718229_header

Grz, Kris.

Friday, 22 July 2011 20:03:15 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Wednesday, 28 July 2010
In Belgium you can never be sure of the weather. It might be great, it might be too hot, it might be too rainy, …
Belgium | Course | MSDN | Tutorial
Wednesday, 28 July 2010 19:24:22 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Tuesday, 16 March 2010

Microsoft launched .toolbox, a new site dedicated on learning Silverlight and Expression.

toolbox

.toolbox features two core learning paths: Design Scenarios and Design Principles. Both begin with teaching basic techniques and build skills and knowledge incrementally. In Design Scenarios, designers and developers learn to create dynamically-rich Silverlight applications using Expression Studio. You will learn to add code-free functionality to designs by following step-by-step tutorials that illustrate how to create interactive user experiences. In Design Principles, you will learn fundamental design concepts (e.g., choosing the right colors and the right fonts) along with tips and techniques in how to apply them to your creations.

One can go for either track and earn leves with that. Each track can be done one by one following a stack or go through the matrix:

toolbox_track

Grz, Kris.

Tuesday, 16 March 2010 13:23:55 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Tuesday, 24 March 2009

I was browsing on the new pages for ASP.NET MVC on www.asp.net and noticed that besides Storefront and Nerddinner there was another tutorial guide available: Contact manager by Stephen Walther. It has currently already 7 tutorials:

Some more reading for me the next days…

Grz, Kris.

Tuesday, 24 March 2009 21:53:39 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Tuesday, 17 March 2009

Just noticed that there are several new videos under the learn section at "_blank">www.asp.net. This time about IIS for ASP.NET. Be sure to check them out. At the moment there are 8 tutorials already.

Developing and Deploying In a Shared Hosting

Install Silverlight

Working with IIS7 Deligated Admin

Install Silverlight

Feature Specific Delegated Management

Install Silverlight

Troubleshooting Production ASP.NET Apps

Install Silverlight

Creating a Site with IIS7 Manager

Install Silverlight

Installing FTP7

Install Silverlight

Bit Rate Throttling

Install Silverlight

IIS7 Playlists

Install Silverlight

Grz, Kris.

ASP.NET | IIS | Learn | Tutorial
Tuesday, 17 March 2009 11:44:05 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Thursday, 05 June 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, 05 June 2008 08:48:59 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Wednesday, 19 December 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.
LINQ | Tutorial | Wiki | Articles
Wednesday, 19 December 2007 09:01:35 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Monday, 19 November 2007

on

Lots to learn, not enough free time unfortunately.

Grz, Kris.

Monday, 19 November 2007 20:18:22 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Sunday, 09 September 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, 09 September 2007 21:25:12 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [1]  | 
# Saturday, 21 July 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, 21 July 2007 11:44:15 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Monday, 25 June 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, 25 June 2007 15:50:18 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Saturday, 28 April 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, 28 April 2007 12:44:52 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [1]  | 
# Saturday, 03 March 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, 03 March 2007 09:50:15 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Thursday, 04 January 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, 04 January 2007 13:25:38 (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
# Monday, 23 October 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, 23 October 2006 11:05:53 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Tuesday, 29 August 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, 29 August 2006 19:21:02 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Friday, 21 July 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, 21 July 2006 19:39:14 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Friday, 07 July 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.

dasBlogMacro_01.png">dasBlogMacro_01_th.png" border=0>
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.

dasBlogMacro_02_01.png" border=0>
Figure 2: locate and choose System.Web

dasBlogMacro_02_02.png" border=0>
Figure 3: Navigate to the bin folder of the compiled bits of dasBlog and select the needed assemblies.

dasBlogMacro_solexpl.png" border=0>
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:

<add macro="mymacros" type="MydasBlogMacros.MyMacros, MydasBlogMacros"/>

Remember I told in the previous part that you could name your solution somewhat else, well here that name comes into play. If you take a look at the previous line you can see this combination: type="TypeName, Name of the assembly". TypeName in this case is NameSpace.ClassName. The name in the macro attribute, in this example mymacros will be used when we want to use a specific macro.

Use the macro in your template:

So at this point we created our macros, configured dasBlog that they exist. Now comes the part where we embed, or better use, our macros so they become visible in the what a visitor can see by altering the templates in the themes. dasBlog ships with several themes out of the box and people can switch between them. You can however push visitors to only have one theme available by deleting the rest of the themes. If you don't this you'll need to do the next steps for every theme if you want those themes to also have your macros available.

Navigate to the theme folder of choice. There you'll see several .css files and 3 files that have the extension .blogtemplate. Because the macros will be used for every item, they contain specific information for a specific item, open the itemTemplate.blogtemplate file. Here you can call a macro with the following syntax:

<%EmailIt("Email it!", "mailLinkStyle")|mymacros%>.

The call can be easily identified, it's the first macro in our example EmailIt. The method takes 2 parameters. After the method call you see the | followed by the name we provided in the macro attribute when we configured the web.config. I also created a new external .css file where I put the specific styles. After that I imported the newly created file into the base.css file with this statement: @import url("mymacros.css");

Resources:

- (1): dasBlog download.
- (2): Compiling the dasBlog source code.
- The class FooMacros in the dasBlog total solution.
- Creating dasBlog macros.

 

Well that's it for this article. I hope you found it interesting and if you create new macros yourself or have questions feel free to use the Comments field to let me know.

Grz, Kris.

kick it on DotNetKicks.com

Friday, 07 July 2006 19:42:12 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [8]  | 
# Monday, 05 June 2006

I read this kind of questions multiple times on the $blank(forums.asp.net,ASP.NET forums). Most of the time it's suggested that one can use one of the events of the grid control they're using to use the FindControl method to find a Label control in one of the template columns and add the current row number to its Text property. I also used to do it like that when I started with ASP.NET.

However it can be done easier, and in markup, without the use of events, and best of all, the grid controls(1) of ASP.NET support the technique.


Figure 1: The GridView, DataGrid, Repeater and DataList controls shown to present the technique.

If Figure 1 you can see that it also supports pagination, which is shown in the GridView control.

Code says more than words so here goes:

    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 DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)

    8     {

    9         DataGrid1.CurrentPageIndex = e.NewPageIndex;

   10         DataGrid1.DataBind();

   11     }

   12 </script>

   13 

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

   15 <head runat="server">

   16     <title>Autonumbering grid controls</title>

   17 </head>

   18 <body>

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

   20     <div>

   21         GridView</div>

   22         <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"

   23             AutoGenerateColumns="False" DataSourceID="SqlDataSource1" PageSize="5">

   24             <Columns>

   25             <asp:TemplateField>

   26                 <ItemTemplate>

   27                     <%# Container.DataItemIndex + 1 %>

   28                 </ItemTemplate>

   29             </asp:TemplateField>

   30                 <asp:BoundField DataField="CategoryName" HeaderText="CategoryName" SortExpression="CategoryName" />

   31                 <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />

   32             </Columns>

   33         </asp:GridView>

   34         <br />

   35         DataGrid

   36         <br />

   37         <asp:DataGrid runat="server" ID="DataGrid1" DataSourceID="SqlDataSource1" AllowPaging="True" OnPageIndexChanged="DataGrid1_PageIndexChanged" PageSize="5">

   38             <Columns>

   39                 <asp:TemplateColumn>

   40                     <ItemTemplate>

   41                         <%# Container.DataSetIndex + 1 %>

   42                     </ItemTemplate>

   43                 </asp:TemplateColumn>

   44             </Columns>

   45         </asp:DataGrid><br />

   46         Repeater<br />

   47         <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">

   48             <ItemTemplate>

   49                 <span style="margin-right:20px;"><%# Container.ItemIndex + 1 %></span>

   50                 <span><%# Eval("CategoryName") %> <%# Eval("Description") %></span><br />

   51             </ItemTemplate>

   52         </asp:Repeater><br />

   53         DataList

   54         <br />

   55         <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1">

   56             <ItemTemplate>

   57                 <%# Container.ItemIndex + 1 %>

   58                 CategoryName:

   59                 <asp:Label ID="CategoryNameLabel" runat="server" Text='<%# Eval("CategoryName") %>'>

   60                 </asp:Label><br />

   61                 Description:

   62                 <asp:Label ID="DescriptionLabel" runat="server" Text='<%# Eval("Description") %>'>

   63                 </asp:Label><br />

   64                 <br />

   65             </ItemTemplate>

   66         </asp:DataList>

   67         <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"

   68             SelectCommand="SELECT [CategoryName], [Description] FROM [Categories]"></asp:SqlDataSource>

   69     </form>

   70 </body>

   71 </html>

For simplicity I used the SqlDataSource control that ships with ASP.NET 2.0 and used the Northwind database (lines 67 - 68). The following lines are of importance: 27, 41, 49 and 57. The + 1 is added each time because of the zero based index.

As you can see, it's each time a very simple addition to the markup of the grid control you're using but it adds that nice extra touch of information that endusers like to see.

Grz, Kris.

(1): I tested it upon the GridView, DataGrid, DataList and Repeater controls.

kick it on DotNetKicks.com

Monday, 05 June 2006 15:27:28 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [2]  |