RTUR.NET

.NET and Open Source: better together

NAVIGATION - SEARCH

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 (2.58 kb) 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 -->

2. 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>
3. 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();
}

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!

Comments (2) -

Hi is there a way we can add AJAX to asp.net PAGES i.e can we prevent the refreshing of page on click of menu? I used update Panel in site.master of my blogengine.net theme but it didnot work.

Any suggestions would be greatly appreciated.
Regards,
Judef

"to asp.net PAGES" == Blogengine.Net Pages

Comments are closed