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

IIS7 hasn't shipped yet but will be available in Vista and Longhorn server. It provides better ways to extend it and configure it. There's also already some nice video content about the subject:

Microsoft also provides the possibility to test drive it on one of their Virtual Labs.

Grz, Kris.

 |  |  | 
Friday, July 21, 2006 8:13:00 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, July 17, 2006

I finally gave Windows Desktop Search a try. It still needs to index quite some files but I already like it a lot. Since I have a lot of documents containing code on my development PC I can use the tool to quickly search in all files at once.

If you're interested you can go the files here: Windows Desktop Search, or take the tour.

I also found an interesting article related to this: Bring Windows Desktop Search Into Visual Studio With Our Cool Add-In. I didn't try that one out yet.

Grz, Kris.

Monday, July 17, 2006 4:50:14 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback

I just found out about this site. It's an overview of free/payware widgets/addins: Team System Widgets.

Grz, Kris.

kick it on DotNetKicks.com

Monday, July 17, 2006 6:09:40 AM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Friday, July 14, 2006
 | 
Friday, July 14, 2006 7:48:57 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [2]  |  Trackback
 Wednesday, July 12, 2006

You read that right: it's free. Take a look at http://www.microsoft.com/windows/virtualpc/. You'll find on this page the great news, whitepapers, ...
Also the announcement was made that Virtual PC 2007 will also be free when it ships.

Grz, Kris.

Wednesday, July 12, 2006 8:06:27 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, July 10, 2006

When ASP.NET 2.0 was still out of reach for most people I already found on the internet a great looking diagram I downloaded in the past. All credits go to the original designer of the diagram: Léon Andrianarivony. Because I couldn't find the original blogpost anymore I decided to share it with you, the readers of this blog. Enjoy!

Grz, Kris.

kick it on DotNetKicks.com

Monday, July 10, 2006 5:48:47 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [2]  |  Trackback
 Sunday, July 09, 2006

I found out about this new page on ASP.NET, thanks to PeteL and Brian Goldfarb: By the Community, For the Community.

The By The Community, For the Community samples series will create ASP.NET samples that are in high demand. These samples will not be created by Microsoft but instead by a select group of ASP.NET community member MVPs. You can see their bios below.

On a regular basis, starting Friday July 7th, we will publish a list of potential samples and allow the community to vote on which sample they are most interested in seeing developed. After the voting ends, the select MVPs will then create the sample using best practices. The samples will be published and then linked to from this page on www.asp.net.

So go out and vote for the stuff that you want these guys to create! Personally I love this idea. There are a lot of smart people out there with an MVP status and they're getting more attention. Just think of the Wrox book MVP hacks for example. The ASP.NET forums also have a bunch of MVP people hanging around to help out other people.

Grz, Kris.

Sunday, July 09, 2006 11:14:02 AM (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:

<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, July 07, 2006 6:42:12 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [8]  |  Trackback

I just installed the latest binaries of dasBlog. If you like to know how to get the latest source code yourself I like to point out to this excellent post: Re-Post of "Compiling the DasBlog Source Code" from DasBlog.info. Also be sure to use the package.bat file at the root of the downloaded bits because publishing, using vs.net 2005, doesn't seem to work out that very well.

I also created several macros, a great feature to have IMHO, of which you can see the result in every post at the bottom. I include links to email, add to delicious, digg or technorati. It's my plan to create an article about this soon.

Grz, Kris.

Friday, July 07, 2006 1:50:51 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Friday, June 30, 2006

Today, in the afternoon, I went to the first part, the next one's tomorrow, about Visual Team System 2005 an event by VISUG of which I'm a member. Thanks to the people from Microsoft we also got a new book to read for free: Wrox' Professional Visual Studio 2005 Team System.

Wrox Professional Visual Studio 2005 Team System

The presentation is given by Steven Wilsens, whom is a Team System MVP and will be joining Microsoft in a while.

I'm looking forward to the next part of the event.

Grz, Kris.

 |  | 
Friday, June 30, 2006 8:23:17 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback
Friday, June 30, 2006 7:29:27 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback

Dynamic updatepanels, bugfixes, ...

I just read it on Nikhil's blog and downloaded it from the the Atlas site.

Details of the new CTP:

UpdatePanel:

  • UpdatePanels can be added to a page dynamically throughout the page lifecycle, including UpdatePanels inside templates. UpdatePanels now also work inside WebParts, and WebParts can be inside UpdatePanels.
  • UpdatePanel will preserve cookies set during an async postback when Response.Redirect() is called. This fixes Login control scenarios where an authorization cookie is set and the user gets redirected to the previous page.

Networking:

  • ServiceMethod uses default error handler if none specified.
  • XsltBridgeTransformer now works with VirtualPathProviders
  • DBNull.Value now should be serialized as null
  • ServiceReferences now support optional InlineProxy attribute for generating service proxies in the page rather than through a serviceurl/js script reference.
  • Fix for scenarios where web service proxy contained the wrong port (webfarms, port forwarding)

Drag and Drop:

  • Drag and drop will no longer produce debug output
  • Interactive HTML elements (input, button, textarea, select, label, anchors with an href) can no longer be dragged directly

Miscellaneous Changes:

  • Date.toFormattedString improvements
  • Client-side data: SaveData fix for strongly-typed DataSets

 

I for one hope that the RTM version is coming close.

Grz, Kris.

Friday, June 30, 2006 6:57:28 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  |  Trackback