User control injection in BlogEngine.NET 1.2

Sep 2, 2007

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.

* $4.95/month BlogEngine.net Hosting – Click Here!

Comments (17) -

James Skemp
James Skemp United States
9/2/2007 7:25:09 PM #

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.

Dan Atkinson
Dan Atkinson United Kingdom
9/3/2007 7:55:36 AM #

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?

Mads Kristensen
Mads Kristensen
9/3/2007 10:41:22 AM #

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

Dan Atkinson
Dan Atkinson United Kingdom
9/3/2007 11:26:21 AM #

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: 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

Mads Kristensen
Mads Kristensen
9/3/2007 12:32:44 PM #

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

Dan Atkinson
Dan Atkinson United Kingdom
9/3/2007 1:11:29 PM #

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

rocky
rocky People's Republic of China
9/3/2007 1:51:59 PM #

BlogEngine.NET 1.2 , I desire it.

Mads Kristensen
Mads Kristensen Denmark
9/3/2007 2:47:52 PM #

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

Dan Atkinson
Dan Atkinson United Kingdom
9/4/2007 6:38:04 AM #

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
Dan Atkinson United Kingdom
9/4/2007 7:02:36 AM #

Scrub that last comment.

"cpc checkout blogengine" is the one.

Domenic Denicola
Domenic Denicola United States
11/11/2007 7:37:27 AM #

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

Kurt LeBlanc
Kurt LeBlanc United States
11/29/2007 6:51:56 PM #

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!

Patrick
Patrick United States
1/11/2008 7:44:59 PM #

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

Kosta
Kosta Canada
4/18/2008 12:24:05 AM #

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?

Mads Kristensen
Mads Kristensen
4/18/2008 6:07:27 AM #

@Kosta,

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

Kosta
Kosta Canada
4/18/2008 6:29:13 AM #

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...

Mads Kristensen
Mads Kristensen
4/18/2008 7:03:40 AM #

@Kosta,

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

Comments are closed

About the author

Mads Kristensen

Mads Kristensen
Program Manager at the Microsoft Web Platform team and founder of BlogEngine.NET.

More...

Month List

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer’s view in any way.