User control injection in BlogEngine.NET 1.2

by Mads Kristensen 2. September 2007 21:30

In the upcoming version of BlogEngine.NET it is now possible to embed standard ASP.NET user controls into the body of a post. We did this because a lot of people have built various user controls over time and it would be a shame not to be able to use them on a blog. This allows developers to put polls, forms and other cool stuff inside a blog post just by creating an .ascx user control.

The injection

Now, let’s say you have a user control called poll.ascx and want to inject it in the middle of the text of a blog post. The poll.ascx file is located in your theme folder, but could be located anywhere. To inject it you just type the following into the editor:

When the post is served it looks for any references to user controls, like the one above, and renders them inside the post. The only limitation is that postbacks will screw up the comment form. Therefore it is suggested that you use AJAX in the form of client-callbacks instead of postbacks. It doesn’t make sense to use postbacks anyway, because that would scroll the page to the top and that is very bad usability.

By injecting user controls in a post you can also place Google ads where ever you want. Just stick your Google JavaScript code in a user control and reference it. This can also be done using the extension model, but might be easier to modify.

I’m very excited about this feature because I can’t imagine all the possibilities it provides to BlogEngine users and what cool controls will be created. The 1.2 version is being released later this September.

Use custom web pages

If you want to create a custom web page instead of injecting user controls, you can still do that the same way as usual. Just place your custom .aspx page in the root and make it inherit from BlogEngine.Core.Web.Control.BlogBasePage instead of System.Web.UI.Page. When doing that it automatically loads your theme and master page around the page. You can then keep the look and feel of your theme, but totally control the content and functionality of your custom page.

* Only $4.95/month ASP.NET & Windows 2008 + IIS 7 Hosting! FREE SQL Included

Tags:

BlogEngine

Comments

9/3/2007 4:25:09 AM #

James Skemp

Mads, this is very, very, cool.

This is a fast moving project, which doesn't suffer from some of the stability issues that other projects out there get stuck on (and fail because of).

It's easy to see that you care about this project, and want to make it a valuable resource for the .NET community.

James Skemp United States |

9/3/2007 4:55:36 PM #

Dan Atkinson

That's a really cool feature Mads!

After I installed BlogEngine on my site, I thought about the one thing I miss in it, jQuery.

When I get home tonight, I'm going to build a jQuery extension for BlogEngine, so that maybe others can play around with it and enjoy it as much as I do!

Is there a way to upload extensions to the blogengine website, for others to download from?

Dan Atkinson United Kingdom |

9/3/2007 7:41:22 PM #

Mads Kristensen

Good idea Dan. There is no community site yet, so you have to put it on your own blog and then we can link to it from the official BE website

Mads Kristensen |

9/3/2007 8:26:21 PM #

Dan Atkinson

OK, thanks for that.

Do you have an extension template for BlogEngine at all?

You know, desired syntax and whatnot.

Also, is there some form of extension description structure? The way WordPress structures its own plugins information is really good in terms of searching and maybe, thinking long-term, it's best to lay down the foundations for the future, in terms of tags, version compatibility, etc. An example for what I'm proposing is below:

Plugin Name: jQuery for BlogEngine.NET
Version: 1.0.0
Plugin URI: http://www.dan-atkinson.com/page/jQuery-for-BlogEngineNET.aspx" rel="nofollow">www.dan-atkinson.com/.../...for-BlogEngineNET.aspx
Author: Dan Atkinson
Author URI: http://www.dan-atkinson.com
Description: Adds the jQuery goodness into your blog.
Tags: jQuery, AJAX, JavaScript, JS

Dan Atkinson United Kingdom |

9/3/2007 9:32:44 PM #

Mads Kristensen

look in the app_code/extensions/ folder to see the ones already there. It should be very very simple

Mads Kristensen |

9/3/2007 10:11:29 PM #

Dan Atkinson

I only have one folder in app_code, and that's named 'controls'. Is this the one you're referring to?

Dan Atkinson United Kingdom |

9/3/2007 10:51:59 PM #

rocky

BlogEngine.NET 1.2 , I desire it.

rocky People's Republic of China |

9/3/2007 11:47:52 PM #

Mads Kristensen

Sorry Dan, the extension model is not in the 1.1 release, but can be downloaded in the latest source code on codeplex.

Mads Kristensen Denmark |

9/4/2007 3:38:04 PM #

Dan Atkinson

Ah right. I think I'll wait until 1.2 is released then, because I don't understand Codeplex enough to download the latest release, and the 1.2 release shows no available release.

I've seen the command line client, but it's about as friendly as a starved goat (which I assume to be quite unfriendly). There doesn't appear to be any kind of sourcesafe/SVN-like resource for source control, although I'm sure there might be.

Dan Atkinson United Kingdom |

9/4/2007 4:02:36 PM #

Dan Atkinson

Scrub that last comment.

"cpc checkout blogengine" is the one.

Dan Atkinson United Kingdom |

11/11/2007 4:37:27 PM #

Domenic Denicola

How would this work if the extension has attributes that are to be set? e.g. <custom:AmazonLink ASIN="1234" Title="Thingy" />.

Domenic Denicola United States |

11/30/2007 3:51:56 AM #

Kurt LeBlanc

This only works using XmlBlogProvider but fails in my test cases if BlogEngine provider set to MSSQLBlogProvider. The blog post renders the injected code simply as "[usercontrol: ~/test.ascx]", for example. Is there a solution for getting this to work correctly?

Otherwise, Great tool!

Kurt LeBlanc United States |

1/12/2008 4:44:59 AM #

Patrick

Is there a solution to get attributes passed into the control?

Patrick United States |

4/18/2008 9:24:05 AM #

Kosta

I'm wondering about the attributes passed into the injected control also.

Has anyone figured out a way to do this?  ...or is it even possible?

Kosta Canada |

4/18/2008 3:07:27 PM #

Mads Kristensen

@Kosta,

Attributes, or properties if you'd like, was introduced in BlogEngine.NET 1.3

Mads Kristensen |

4/18/2008 3:29:13 PM #

Kosta

Sweet!

...what's the syntax?

I have tried a few combinations but can't seem to get it to work.

Is there any documentation you can point me to? I've had no luck finding anything...

Thanks...

Kosta Canada |

4/18/2008 4:03:40 PM #

Mads Kristensen

@Kosta,

Check out this post blog.madskristensen.dk/.../...NET-13-features.aspx

Mads Kristensen |

Comments are closed

About the slave

Mads Kristensen Mads Kristensen
Web developer at ZYB and founder of BlogEngine.NET. More...

LinkedIn ZYB Facebook Last.fm Twitter View Mads Kristensen's profile on Technorati

The Lounge

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008