Fun with Artisteer in C#


Author Message
Stephen Anderson

Posted: 6/18/2010
Quote message 

I like using Artisteer. I have used the C# project and the html project outputs to create ASP.NET solutions.

There are pros and cons to both approaches.

C# Project:
Pros:
The project is already built and the markup in the aspx pages is minimal due to the artisteer block and article controls.

Cons:
When my code breaks, it sometimes breaks in the code used by the article and block controls to render the childcontrols. This makes it difficult to find the source of the problem when debugging. I usually find myself wondering "Is this not working because it is inside this other control or is it something else".

I have to manually reference each control that is inside an artisteer block or article control if I want to acces any of it's properties at runtime.

HTML Output:
Pros:
I don't have to use the artisteer block and article controls with their problems mentioned above.

I can adapt the generated output to create my own ASP.NET project and split up the generated markup in the page.html file to create my own masterpage or nested masterpages (to allow for different or no sidebars, etc).

Cons:
Without using the artisteer article and block controls, the html markup on my content pages must include all those many many lines of divs in order to render the pretty blocks and articles.

Here's my tip to get the best of both worlds

What I do now is to use the HTML generated output and create my own masterpage or nested masterpages.

Use literal controls and a helper class to generate all the many lines of markup required to render the pretty articles and blocks.

That way I keep my markup to a minimum and I get to avoid having to place my content inside artisteer article and block controls while getting the benefits of the pretty blocks and articles.

Here's an example.

In the aspx page:

<asp:Literal ID="Article1Start" runat="server" />
hi
<asp:Literal ID="Article1End" runat="server" />


in the codebehind:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Article1Start.Text = BlocksAndArticles.ArticleStart("Yo Peeps!");
Article1End.Text = BlocksAndArticles.ArticleEnd();
}
}


...and here's the code for the helper class (don't forget to add a reference to System.Text for the StringBuilder)

public static class BlocksAndArticles
{
public static string ArticleStart(string caption)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(@"<div class=""art-Post"">");
sb.AppendLine(@"<div class=""art-Post-tl""></div>");
sb.AppendLine(@"<div class=""art-Post-tr""></div>");
sb.AppendLine(@"<div class=""art-Post-bl""></div>");
sb.AppendLine(@"<div class=""art-Post-br""></div>");
sb.AppendLine(@"<div class=""art-Post-tc""></div>");
sb.AppendLine(@"<div class=""art-Post-bc""></div>");
sb.AppendLine(@"<div class=""art-Post-cl""></div>");
sb.AppendLine(@"<div class=""art-Post-cr""></div>");
sb.AppendLine(@"<div class=""art-Post-cc""></div>");
sb.AppendLine(@"<div class=""art-Post-body"">");
sb.AppendLine(@"<div class=""art-Post-inner"">");
sb.AppendLine(@"<div class=""art-PostMetadataHeader"">");
sb.AppendLine(@"<h2 class=""art-PostHeader"">");
sb.AppendLine(caption);
sb.AppendLine(@"</h2>");
sb.AppendLine(@"</div>");
sb.AppendLine(@"<div class=""art-PostContent"">");

return sb.ToString();
}

public static string ArticleEnd()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(@"</div>");
sb.AppendLine(@"<div class=""cleared""></div>");
sb.AppendLine(@"</div>");
sb.AppendLine(@"<div class=""cleared""></div>");
sb.AppendLine(@"</div>");
sb.AppendLine(@"</div>");

return sb.ToString();
}

public static string BlockStart(string caption)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(@"<div class=""art-Block"">");
sb.AppendLine(@"<div class=""art-Block-tl""></div>");
sb.AppendLine(@"<div class=""art-Block-tr""></div>");
sb.AppendLine(@"<div class=""art-Block-bl""></div>");
sb.AppendLine(@"<div class=""art-Block-br""></div>");
sb.AppendLine(@"<div class=""art-Block-tc""></div>");
sb.AppendLine(@"<div class=""art-Block-bc""></div>");
sb.AppendLine(@"<div class=""art-Block-cl""></div>");
sb.AppendLine(@"<div class=""art-Block-cr""></div>");
sb.AppendLine(@"<div class=""art-Block-cc""></div>");
sb.AppendLine(@"<div class=""art-Block-body"">");
sb.AppendLine(@"<div class=""art-BlockHeader"">");
sb.AppendLine(@"<div class=""l""></div>");
sb.AppendLine(@"<div class=""r""></div>");
sb.AppendLine(@"<div class=""art-header-tag-icon"">");
sb.AppendLine(@"<div class=""t"">");
sb.AppendLine(caption);
sb.AppendLine(@"</div>");
sb.AppendLine(@"</div>");
sb.AppendLine(@"</div><div class=""art-BlockContent"">");
sb.AppendLine(@"<div class=""art-BlockContent-body"">");
sb.AppendLine(@"<div>");

return sb.ToString();
}

public static string BlockEnd()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(@"</div>");
sb.AppendLine(@"<div class=""cleared""></div>");
sb.AppendLine(@"</div>");
sb.AppendLine(@"</div>");
sb.AppendLine(@"<div class=""cleared""></div>");
sb.AppendLine(@"</div>");
sb.AppendLine(@"</div>");

return sb.ToString();
}
}


This is my first tip on any forum. Please let me know if this is useful to anyone. Also please feel free to criticise the hell out of it.

Thanks
 
Allan K. Nielsen

Posted: 4/24/2011
Quote message 

Ah - sorry, the code sample got messed up due to "{" and "}" tags.
The "ToolboxData" line is supposed to look like this:

[ToolboxData("<?0?:ArticlePanel runat=\"server\"></?0?:ArticlePanel>")]


Where "?" should be replaced with "{" and "}" (it the previous post those cause my entire message to be inserted twice inside that line).