Apr
10
Posted by:
Michael Washington
4/10/2007

The DotNetNuke Framework cannot assume that the web server it is running on has ASP.NET AJAX installed. In order to handle this a new class was created in DotNetNuke.Framework.AJAX which provides methods that developers can use to leverage AJAX in their solutions.


Setting Dependencies
One option in developing a DotNetNuke ASP.NET AJAX module is indicating the System.Web.UI.ScriptManager dependency in the module configuration setting:

Modules can optionally specify a semi-colon delimited list of Dependencies which their module requires (for example, indicate System.Web.UI.ScriptManager when your module requires that the site have ASP.NET AJAX installed and enabled). Then, during the installation of the module, if the environment does not support a specific permission, a message will be displayed to the user and the module will not be installed.

IsInstalled and RegisterScriptManager()
If you want to use ASP.NET AJAX functionality only when it is available, you can decide not to use the Dependency and use the IsInstalled flag and the IsEnabled setting.
The IsInstalled flag indicates whether AJAX is available in the environment and the IsEnabled setting must be used by developers to tell DotNetNuke that their module/skin is using AJAX on the page.
IsInstalled
The IsInstalled flag is simple to use and can be checked before any ASP.NET AJAX functionality is called. The function returns a Boolean value (true or false)
DotNetNuke.Framework.AJAX.IsInstalled
RegisterScriptManager()
AJAX needs to be registered very early in the page life cycle for it to be recognized, so DNN inserts the ScriptManager into the page dynamically. If modules loaded on the page use the RegisterScriptManager() method, DNN knows that the page requires AJAX. If no modules use RegisterScriptManager(), then DNN thinks that the page does not require AJAX - and at the Render stage it will REMOVE the ScriptManager from the page (since it thinks it is not necessary and does not need the extra overhead associated).
If DotNetNuke.Framework.AJAX.IsInstalled Then
DotNetNuke.Framework.AJAX.RegisterScriptManager()
End If
Supports Partial Rendering

The easiest way to deploy ASP.NET AJAX with DotNetNuke is to enable the Supports Partial Rendering flag in the definition for the module control (Host Menu > Module Definitions > Edit Module Definition > Edit Module Control).
Using this setting you only have to check DotNetNuke.Framework.AJAX.IsInstalled() if you have specific ASP.NET AJAX functionality that you will need to disable if ASP.NET AJAX is not available (see Creating Secure DotNetNuke ASP.NET AJAX Web Services for an example of when this is needed).
By default the Supports Partial Rendering flag is False for all controls. Only if the developer of the module explicitly sets the Supports Partial Rendering flag to True in their *.dnn installation manifest, or the Portal administrator checks the Supports Partial Rendering box, will it be wrapped by an Update Panel (and only if AJAX is installed ).
This functionality provides the simplest, most effective way for a module developer to create an application which works in the lowest common denominator environment - but is also able to take advantage of partial rendering when it is available.
The availability of this feature means that a module developer should seldom ever need to check DotNetNuke.Framework.AJAX.IsInstalled() or include an Update Panel in their module controls. Instead, the module developer only needs to set the Supports Partial Rendering flag in situations where it makes sense
However, if a control already contains JavaScript for dynamic behaviors, wrapping the control in an Update Panel has the potential to break the control's functionality.
Sample ASP.NET AJAX Application

The sample demonstrates ASP.NET AJAX support. All that was done was to enable the Supports Partial Rendering flag in the user control for the module.
The AJAX sample code can be downloaded at this link. (it will only work with DotNetNuke 4.5.0 or higher)
Imports DotNetNuke
Imports System.Collections.Generic
Namespace DotNetNuke.Modules
Partial Class Ajax
Inherits Entities.Modules.PortalModuleBase
Dim CurrentPageIndex As Integer
Protected Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
ShowData(1)
End If
End Sub
Private Sub ShowData(ByVal intCurrentPageIndex As Integer)
Dim mySqlString As New StringBuilder()
mySqlString.Append("SELECT FriendlyName, Description ")
mySqlString.Append("FROM {databaseOwner}{objectQualifier}DesktopModules ")
mySqlString.Append("ORDER BY FriendlyName")
Dim colDesktopModules As New List(Of myDesktopModules)
Using dr As IDataReader = _
CType(DataProvider.Instance().ExecuteSQL(mySqlString.ToString(), Nothing), IDataReader)
While dr.Read
Dim objDesktopModules As New myDesktopModules()
objDesktopModules.FriendlyName = Convert.ToString(dr("FriendlyName"))
objDesktopModules.Description = Convert.ToString(dr("Description"))
colDesktopModules.Add(objDesktopModules)
End While
End Using
Dim pagedData As New PagedDataSource()
pagedData.DataSource = colDesktopModules
pagedData.AllowPaging = True
pagedData.PageSize = 10
pagedData.CurrentPageIndex = intCurrentPageIndex - 1
Me.lblTotalPages.Text = Convert.ToString(pagedData.PageCount)
Me.lblCurrentPage.Text = Convert.ToString(pagedData.CurrentPageIndex + 1)
If pagedData.IsFirstPage Then
btnPrevious.Visible = False
Else
btnPrevious.Visible = True
End If
If pagedData.IsLastPage Then
btnNext.Visible = False
Else
btnNext.Visible = True
End If
Me.GridView1.DataSource = pagedData
Me.GridView1.DataBind()
End Sub
Protected Sub Next_Click(ByVal sender As Object, ByVal e As System.EventArgs)
CurrentPageIndex = Convert.ToInt32(Me.lblCurrentPage.Text) + 1
ShowData(CurrentPageIndex)
End Sub
Protected Sub btnPrevious_Click(ByVal sender As Object, ByVal e As System.EventArgs)
CurrentPageIndex = Convert.ToInt32(Me.lblCurrentPage.Text) - 1
ShowData(CurrentPageIndex)
End Sub
End Class
Public Class myDesktopModules
Dim _FriendlyName As String
Dim _Description As String
Public Property FriendlyName() As String
Get
Return _FriendlyName
End Get
Set(ByVal value As String)
_FriendlyName = value
End Set
End Property
Public Property Description() As String
Get
Return _Description
End Get
Set(ByVal value As String)
_Description = value
End Set
End Property
End Class
End Namespace
15 comment(s) so far...
Re: DotNetNuke 4.5 Features: Creating A DotNetNuke Module using ASP.NET AJAX
We appreciate the quick response by the DNN team in incorporating the ASP.NET Ajax into the DNN framework!
By BrandonHaynes on
3/12/2007
|
Re: DotNetNuke 4.5 Features: Creating A DotNetNuke Module using ASP.NET AJAX
Great news to see this coming in DNN 4.5 - No more crazy edits to the web.config. Yea!!!
Is the default doctype being changed to support this also ?
By jbonnie on
3/12/2007
|
Re: DotNetNuke 4.5 Features: Creating A DotNetNuke Module using ASP.NET AJAX
Supergroovy.
Great solution to the problem.
I'm curious where the UpdatePanel control is integrated. The container?
By wesclyburn on
3/12/2007
|
Re: DotNetNuke 4.5 Features: Creating A DotNetNuke Module using ASP.NET AJAX
Hhhhmmm... it is beautifull, the way DotNetNuke accomodate AJAX.NET :-) DotNetNuke.Framework.AJAX ? Cooolll...
Fortunately, the architecture like this. Than it is too tight integrated with AJAX.NET (it will make AJAX.NET mandatory :: Want to install DotNetNuke ? Install AJAX.NET first !!! How terrible it is)
Thanks for DotNetNuke team :-) (especially for nice architecture)
March 15 is 3 days again :-)
I would be patient.
By muhammad_sudirman on
3/12/2007
|
Re: DotNetNuke 4.5 Features: Creating A DotNetNuke Module using ASP.NET AJAX
Awesome...thanks Michael!
By favance on
3/16/2007
|
Re: DotNetNuke 4.5 Features: Creating A DotNetNuke Module using ASP.NET AJAX
Michael:
Have you played with the ASP.Net AJAX Control Toolkit? How difficult would it be to use those controls in 4.5? They look really cool.
In case you haven't seen them they are here: http://ajax.asp.net/ajaxtoolkit/Default.aspx
Carlos
By carlosrafi on
3/22/2007
|
Re: DotNetNuke 4.5 Features: Creating A DotNetNuke Module using ASP.NET AJAX
The ASP.Net AJAX Control Toolkit works great with the DotNetNuke 4.5 RC that I am testing with :)
By AdefWebserver on
3/23/2007
|
Re: DotNetNuke 4.5 Features: Creating A DotNetNuke Module using ASP.NET AJAX - *Updated*
Great article Michael. Can we assume that the core DNN modules will be supporting partial rendering very soon? I always thought it made sence for DNN in its module format to go AJAX. I know Jon Henning has talked about it for a while. Your not planning to write anything on the best way to architect a AJAX DNN module that relies on an AJAX webservice to retrieve its data for display rather then partial rendering? Having used these recently and seeing how nice and easy it is to work with JSON I can see huge benifits inside all DNN modules. It could be very possible to have DNN site that operates without any postbacks. John.
By Spankmebandit on
3/29/2007
|
Re: DotNetNuke 4.5 Features: Creating A DotNetNuke Module using ASP.NET AJAX - *Updated*
Looks like i didn't read ahead....you have writting two blogs about webservices with DNN very good!
By Spankmebandit on
3/29/2007
|
Re: DotNetNuke 4.5 Features: Creating A DotNetNuke Module using ASP.NET AJAX - *Updated*
AdefWebserver, Can you post (or someone else who has already figured it) an example how the AJAX Control Toolkit can be embedded into a DNN module?
By baychev on
4/10/2007
|
Re: DotNetNuke 4.5 Features: Creating A DotNetNuke Module using ASP.NET AJAX - *Updated*
AdefWebserver,
I had problems with my module that has a AJAX Control Toolkit control (Calendar).
What I did to fix them,
1. Enable the Supports Partial Rendering flag in the definition for the module control (Host Menu > Module Definitions > Edit Module Definition > Edit Module Control).
2. remove the ScriptManager from your module ascx file.
3. My module ascx file does't inherits from DotNetNuke.Framework.AJAX, I left it as is.
By wangwei18 on
4/15/2007
|
Re: DotNetNuke 4.5 Features: Creating A DotNetNuke Module using ASP.NET AJAX - *Updated*
Hello. Thanks for a nice article. But I have a little problem. In my module I have an UpdatePanel with a button and a label(label1) in it, and an another label outside the UpdatePanel (label2). So when I click the button I want the first label to get the current time. And in the page load method I set the label2 to the current time also. But when I click the button both labels update. I didn't have this problem with DNN 4.4.1 (using Vladan's Method). I have the opinion that DNN 4.5.0 Updates the whole module. What am I doing not right ? Please Help !!!!
By tigertop on
4/15/2007
|
Re: DotNetNuke 4.5 Features: Creating A DotNetNuke Module using ASP.NET AJAX - *Updated*
Thanks Micheal, your posts helps me a lot. keep up the good work.
By fagirman on
4/17/2007
|
Re: DotNetNuke 4.5 Features: Creating A DotNetNuke Module using ASP.NET AJAX - *Updated*
Looking for more details on creating dotnetnuke dynamic modules with visual studio 2005. Any references?
- Jaswant Singh Rana
By jaswantsinghrana on
5/9/2007
|
Re: DotNetNuke 4.5 Features: Creating A DotNetNuke Module using ASP.NET AJAX - *Updated*
Does this mean, the existing/default installation of the DNN 4.5.x, does not have the AJAX configuration done ?
Can't we have the pre-built AJAX enabled distribution from the core ?
Is this http://asp.net/learn/videos/view.aspx?tabid=63&id=81 of any use ?
By IndianGuru on
6/12/2007
|