随着即将在3月15号发布的DNN4.5 大家期待已久的对Asp.net Ajax的支持将在此版中发布。
因为Asp.net Ajax 是独立于DNN安装的,所以DNN框架并不能保证你所应用的服务器是否安装Asp.net Ajax, 因此新版的DNN中增加了一个新的类DotNetNuke.Framework.AJAX, 这个类中所提供的方法可以帮助开发者判定是否可以把AJAX应用于你的方案中。
模块配置 Dependencies
开发DotNetNuke ASP.NET AJAX 模块其中的一种方法是指明System.Web.UI.ScriptManager 的从属关系在模块设置中(module configuration setting)
模块可以随意指定多个从属程序集根据需要,用分号分隔开。例如填入System.Web.UI.ScriptManager 即可应用相应功能, 但前提要求你的服务器支持Ajax.。 之后在安装模块的时候如果运行环境不符合将会有警告提示并且中断安装。
IsInstalled 和 IsEnabled
如果你希望自动判断何时使用ASP.NET AJAX 就可以使用IsInstalled和IsEnabled来设置
IsInstalled 可以判断你所应用的系统是否安装了Asp.net Ajax
IsEnabled 设置是由开发者设定是否在所开发的模块/皮肤中应用AJAX
IsInstalled
IsInstalled 使用很简单可以在调用Asp.net Ajax 功能之前用来判断。它将会返回true / false
IsEnabled
IsEnabled 设置是由开发者设定是否在所开发的模块/皮肤中应用AJAX
ASP.NET AJAX 应用样例
AJAX 样例可以在此下载 (需要DNN4.5以上版本才可运行)
样例示范如何应用ASP.net Ajax在run-time
2 Imports System.Collections.Generic
3
4 Namespace DotNetNuke Namespace DotNetNuke.Modules
5Partial Class AjaxClass Ajax
6 Inherits Entities.Modules.PortalModuleBase
7 Dim CurrentPageIndex As Integer
8 Dim boolUsingAjax As Boolean = False
9
10 Protected Sub Page_Load()Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
11
12 If DotNetNuke.Framework.AJAX.IsInstalled() Then
13 If dllAjax.SelectedValue = "Using Ajax" Then
14 boolUsingAjax = True
15 Else
16 boolUsingAjax = False
17 End If
18 Else
19 boolUsingAjax = False
20 End If
21
22 If boolUsingAjax = True Then
23 DotNetNuke.Framework.AJAX.IsEnabled = True
24 Else
25 DotNetNuke.Framework.AJAX.UpdatePanelControl.Visible = False
26 End If
27
28 If Not Page.IsPostBack Then
29 ShowData(1)
30 End If
31
32 End Sub
33
34 Private Sub ShowData()Sub ShowData(ByVal intCurrentPageIndex As Integer)
35
36 Dim mySqlString As New StringBuilder()
37
38 mySqlString.Append("SELECT FriendlyName, Description ")
39 mySqlString.Append("FROM {databaseOwner}{objectQualifier}DesktopModules ")
40 mySqlString.Append("ORDER BY FriendlyName")
41
42 Dim colDesktopModules As New List(Of myDesktopModules)
43
44 Using dr As IDataReader = _
45 CType(DataProvider.Instance().ExecuteSQL(mySqlString.ToString(), Nothing), IDataReader)
46 While dr.Read
47 Dim objDesktopModules As New myDesktopModules()
48 objDesktopModules.FriendlyName = Convert.ToString(dr("FriendlyName"))
49 objDesktopModules.Description = Convert.ToString(dr("Description"))
50 colDesktopModules.Add(objDesktopModules)
51 End While
52 End Using
53
54 Dim pagedData As New PagedDataSource()
55 pagedData.DataSource = colDesktopModules
56 pagedData.AllowPaging = True
57 pagedData.PageSize = 10
58 pagedData.CurrentPageIndex = intCurrentPageIndex - 1
59
60 Me.lblTotalPages.Text = Convert.ToString(pagedData.PageCount)
61 Me.lblCurrentPage.Text = Convert.ToString(pagedData.CurrentPageIndex + 1)
62
63 If pagedData.IsFirstPage Then
64 btnPrevious.Visible = False
65 Else
66 btnPrevious.Visible = True
67 End If
68 If pagedData.IsLastPage Then
69 btnNext.Visible = False
70 Else
71 btnNext.Visible = True
72 End If
73
74 Me.GridView1.DataSource = pagedData
75 Me.GridView1.DataBind()
76
77 End Sub
78
79 Protected Sub Next_Click()Sub Next_Click(ByVal sender As Object, ByVal e As System.EventArgs)
80 CurrentPageIndex = Convert.ToInt32(Me.lblCurrentPage.Text) + 1
81 ShowData(CurrentPageIndex)
82 End Sub
83
84 Protected Sub btnPrevious_Click()Sub btnPrevious_Click(ByVal sender As Object, ByVal e As System.EventArgs)
85 CurrentPageIndex = Convert.ToInt32(Me.lblCurrentPage.Text) - 1
86 ShowData(CurrentPageIndex)
87 End Sub
88End Class
89
90Public Class myDesktopModulesClass myDesktopModules
91 Dim _FriendlyName As String
92 Dim _Description As String
93 Public Property FriendlyName()Property FriendlyName() As String
94 Get
95 Return _FriendlyName
96 End Get
97 Set(ByVal value As String)
98 _FriendlyName = value
99 End Set
100 End Property
101 Public Property Description()Property Description() As String
102 Get
103 Return _Description
104 End Get
105 Set(ByVal value As String)
106 _Description = value
107 End Set
108 End Property
109
110End Class
111
112End Namespace
113
114
Host Setting中的 ASP.NET AJAX 局部渲染
此外, Host Setting 中加入了一个新的AJAX设置Partial Rendering Enabled?(局部渲染设置) 在Host Setting -> Performance Setting, 这个开启这个设置可以应用UpdatePanels来加速admin模式中屏幕上方管理模块的读取速度
原文:Michael Washington
http://www.dotnetnuke.com/Community/BlogsDotNetNuke/tabid/825/EntryID/1358/Default.aspx