BlogEngine and ASP.NET AJAX

As you can read on official site, BlogEngine does support Ajax. The approach it uses - it relays on few simple helper JavaScript routines (can be found in BlogEngine.Core/Web/Scripts/blog.js) and hand-crafter JavaScript functions in the UI code to perform basic callbacks. BlogEngine does not support Ajax.Net (aka Atlas or ASP.NET 2.0 AJAX Extensions in its latest incarnation) out of the box, and for a good reason. Ajax.Net is a dependent technology. You can't just throw Ajax DLLs in the /Bin folder and hope it will work - most likely it won't. The reason is that Microsoft's Ajax libraries require full trust to run, and if this is fine on your local machine, where you can grant yourself all rights in the world, your host might (and should) be far less generous.

The twist here is that if you put same libraries in the GAC (global assembly cache) it only need medium trust, which is a standard policy for most of the hosting environments. So basically you are dependent on your host to run Ajax the Microsoft way. And there are very good reasons you want this one - if you going to build things on top of BlogEngine, that might really benefit from Ajax Extensions, for example.

Now, how do you know that your server equipped with everything you need to run Ajax? All right, you might ask support person and, if you lucky, may be you'll get an answer. May be even this support guy really knows his stuff - if you super lucky. But it is not that hard to take initiative in your own hands - and may be learn a thing or two along the way (always might come in handy) and be 100% sure if this is working for you. Here is the way:

  1. Download web.config.zip and copy all chunks of code marked with "ajax start" - "ajax end" in your own Web.Config file (see example below).
<!-- ajax start -->
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<!-- ajax end -->
  1. In your theme's SidePanel.ascx file, scroll all the way down and copy and paste this code:
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div class="box">
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br /><br />
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
  1. In the code behind file (SidePanel.ascx.cs), add button click event (simply copy and paste code below):
protected void Button1_Click(object sender, EventArgs e)
{
    Label1.Text = DateTime.Now.ToString();
}

ajax-1.png That's all you need; now run your web site and look at the side bar, it should have label and button at the bottom. If you can see it, click the button and make sure that every click updates timer and there is no page flicking (status bar in the browser should be empty and no page reload happening). If this is what you got - congratulations, you've got Ajax.Net up and running and can do loads of good things with it (just visit Ajax.Net to get some ideas on what you have under your disposal). As far as I know, all ASP.NET accounts on GoDaddy have Ajax enabled. If your hosting provider does not support this feature - you might ask him to consider!

About RTUR.NET

This site is all about developing web applications with focus on designing and building open source blogging solutions. Technologies include ASP.NET Core, C#, Angular, JavaScript and more.