This project is read-only.
Project Description
FluentTags for ASP.NET makes it easier to write valid (x)html code.

User the power of of Intellisense and a fluent interface to quickly make valid html.

Extremely useful for building complicated html structures (menus, controls, filters, ajax enabled controls).

FluentTags now available on Nuget

https://nuget.org/packages/FluentTags

PM> Install-Package FluentTags

Motivation
I was dissatisied with building complex html structures using the templating structures available in ASP.NET pages. But building html with the built in classes is even more clunky.

With Fluent Tags you can take advantage Visual Studio intellisense while using this HTML Domain Specific Language (DSL) to create compact, maintainable code.

I've used this library for over 3 years and I find myself missing it anytime I have to hand code HTML. I find that I can quickly create complex valid markup for menus, deeply nested structures and complex ajax controls, while keeping my sanity.

You can take advantage of the compiler to check your syntax. If it compiles, there's a good change it is valid (of course that's not guaranteed, because you can subvert the type system by simply adding a control, however I think the trade off for flexibility is worth it).

Sample Code

// create a new div tag
var div = new DivTag();
// create a new table that is a child of the div tag
var table = div.Table().Style("text-align:center;");
// add a row and some fields to the table
table.TR()
    .TD("some text").End()
    .TD("some other text").End();

FluentTags with with ASP.NET Forms code. You can nest ASP.NET controls within your fluent tags.

Fluent Tags inheret from the HtmlGenericControl class, so they play well with asp.net forms.

In Code Behind:
Button b = new Button();
b.Text = "This Causes a postback";
b.Click += (s, evt) =>
{
    // DivPlaceHolder is defined in the page as a PlaceHolder control
    DivPlaceHolder.Controls.Add(new DivTag().Text("The button postback Worked!").Style("color:red;").End());
};

Button b2 = new Button();
b2.Text = "This Causes a postback";
b2.Click += (s, evt) =>
{
    DivPlaceHolder.Controls.Add(new DivTag().Text("The button2 postback Worked!").Style("color:red;").End());
};

t.TR()
    .TD().AddControl(b).End()
    .TD().AddControl(b2).End()
.End();

Snippet from ASP.NET page (control, etc):

<body>
    <form id="form1" runat="server">
    <div>
    <asp:PlaceHolder ID="DivPlaceHolder" runat="server" ></asp:PlaceHolder>
    </div>
    </form>
</body>

Last edited May 17, 2012 at 10:54 PM by pragmatic, version 10