::::
::English :: Dúnadan Blog
Module Border Module Border
  Categories   Minimize

Module Border Module Border
Module Border Module Border
  Renata's Pics   Minimize

Module Border Module Border
Module Border Module Border
  Dunadan's Blog   Minimize

Oct 18

Written by: Dunadan Raptor
10/18/2007

It's incredibly easy to use AJAX in the DNN 4.5.X versions. In this post I describe the two ways in which you may use AJAX in a DNN module.

Use Control Definitions
Assuming AJAX is already installed in the web server that runs DNN, a module will be dynamically wrapped in an Update Module by doing one of two things:

1) Adding the line below to the control node of a control in the .dnn manifest:

<supportspartialrendering>truesupportspartialrendering>

 2) Select de checkbox for Supports Partial Rendering in the control definition for the control that will use AJAX. Control definitions are reached after selecting a control to edit in a specific Module Definition in Host>Module Definitions>.

When the Partial rendering is enabled, the Microsoft Ajax Library can be used as well as the popular Control Toolkit.

Try this simple example to test a module that has been AJAX-enabled through module definitions. Add a Label and an UpdatePanel to the view control of a module. The put a second Label and a Button inside the UpdatePanel.

Add an empty click event for the Button to create a postback. Then in the Page_Load event  add a timer and assign the current datetime value to the labels.

System.Threading.Thread.Sleep(3000)

Label1.Text = DateTime.Now()

Label2.Text = DateTime.Now()

Clicking on the button shpould only update the datetime value of the label inside the update panel while the first one is unchanged.

Developer control
Remember that there can exist one and only one ScriptManager object in a page and since Dotnetnuke uses a single page, it's only logical that the framework and not the modules should be responsible of adding it dynamically. That is exactly what the Dotnetnuke.Framework.Ajax class does. The class has 8 methods besides its constructor:

Taken from the class documentation:

  1. AddScriptManager:

    AddScriptManager is used internally by the framework to add a ScriptManager control to the page

  2. ContentTemplateContainerControl

    ContentTemplateContainerControl gets a reference to the ContentTemplateContainer control within an UpdatePanel

  3. CreateUpdatePanelControl:

    UpdatePanelControl dynamically creates an instance of an UpdatePanel control

  4. IsInstalled:

    IsInstalled can be used to determine if AJAX is installed on the server

  5. RegisterScriptManager:

    RegisterScriptManager must be used by developers to instruct the framework that AJAX is required on the page

  6. RemoveScriptManager:

    RemoveScriptManager will remove the ScriptManager control during Page Render if the RegisterScriptManager has not been called

  7. ScriptManagerControl:

    ScriptManagerControl provides a reference to the ScriptManager control on the page

  8. SetScriptManagerProperty:

    SetScriptManagerProperty uses reflection to set properties on the dynamically generated ScriptManager control

It is possible to use IsInstalled() to determine if AJAX is installed in the web server, and couple dwith RegisterScriptManager Dotnetnuke will add the ScriptManager control to the page so that the module can use Ajax. The result of the previous example will be the same, but without enabling partial rendering in the module.

If DotNetNuke.Framework.AJAX.IsInstalled() Then

DotNetNuke.Framework.AJAX.RegisterScriptManager()

'Do some stuff

End If

Copyright ©2007 Dunadan Raptor

Tags:

13 comments so far...

Re: Using AJAX in DNN 4.5

Thank you! a useful explanation. You dont say where the code "if dotnetnuke.framework.ajax.isinstalled()..." should go, but it seems to me it goes in the pageload BEFORE the testing for IsPostBack. Do you agree?

By John Braga on   4/15/2007

Re: Using AJAX in DNN 4.5

Yes it goes in Page_Load

By on   4/15/2007

Displaying an animated gif in a Dotnetnuke module with AJAX

  After enabling AJAX, it's pretty easy to declaratively add an animated image using the UpdateProgress control from the Toolkit controls and an animated gif image. This post assumes you already ...
# Mi Bitácora web

By TrackBack on   4/16/2007

Re: Using AJAX in DNN 4.5

Hi, Hot to set AsyncPostBackTimeout Property of ScriptManager. Please help me! Because I want the page refresh a long time (10 hours ) ...

By Anh Ta on   6/27/2007

Re: Using AJAX in DNN 4.5

First set a reference to the scriptmanager control in the page:
Dim sm As ScriptManager = DotNetNuke.Framework.AJAX.ScriptManagerControl(Page)
Then assignt the value to the property:
sm.AsyncPostBackTimeout = 600

By on   6/27/2007

Re: Using AJAX in DNN 4.5

Setting sm As ScriptManager = DotNetNuke.Framework.AJAX.ScriptManagerControl(Page) doesn't work. I am using c# and have support partial rendering checked in my module. How would I use RegisterAsyncPostBackControl for checkbox inside the datagrid.

By Sh on   9/12/2007

Re: Using AJAX in DNN 4.5

Fix your image paths.

By Recursor on   9/12/2007

Re: Using AJAX in DNN 4.5

Thanks, I missed these on site migration.

By hooligannes on   9/12/2007

Re: Using AJAX in DNN 4.5.X

I have a problem with a live site where AJAX is installed (checked by using the "inInstalled" method) and the support partial rendering is checked on, but I am still getting full postbacks rather than AJAX updates.

Any idea's as to what could be causing this?

By Richard on   5/8/2008

Re: Using AJAX in DNN 4.5.X

Disable and re-enable AJAX in Host> Host settings +Other Settings

By hooligannes on   5/8/2008

Re: Using AJAX in DNN 4.5.X

Hi,

Can you clarify the following statement, that you mentioned on the above procedure?

--->Try this simple example to test a module that has been AJAX-enabled through module definitions.

What do you mean by AJAX-enable module? I used the dynamic module template, coupled with your method, and it hanged whenever I add AJAX updatePanel. Any suggestion? Thanks so much.

By nix on   5/30/2008

Re: Using AJAX in DNN 4.5.X

I forgot to include the warning that I got whenever I add the AJAX script manager. It states:

Module load warning. One or more of the modules on this page did not load...

Thank you very much for your help.

By nix on   5/30/2008

Re: Using AJAX in DNN 4.5.X

Try taking a look at your log, or debug the module to find the reason why the module is not loading. I have a forum at this site, and we may continue discussion there.

By hooligannes on   5/30/2008

Your name:
Title:
Comment:
Add Comment    Cancel  
Module Border Module Border