Tuesday, September 23, 2008

Ajax Update panel in DotNetNuke 4.0 or upper

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. For detail about this the following page can be visited -

Creating A DotNetNuke Module using ASP.NET AJAX

But without following the instructions in this page, you can add ajax support in your dotnetnuke module easily. Follow the instruction step by step:

1. instead of ajax update panel add an asp:panel in the module.

2. override the - void OnInit(EventArgs e) method of module i.e. asp.net custom control.

3. In the override OnInit() method register DotNetNuke Ajax Script Manager by calling the method DotNetNuke.Framework.AJAX.RegisterScriptManager().

4 . Then add your asp:panel for ajax support by calling method DotNetNuke.Framework.AJAX.WrapUpdatePanelControl(#asppanelID#, true);

5. You can also allow postback of this module for a specific control in the asp:panel by calling DotNetNuke.Framework.AJAX.RegisterPostBackControl(#aspPostBackEnableControl#).

Sample code block:

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
try
{
if (DotNetNuke.Framework.AJAX.IsInstalled())
{
DotNetNuke.Framework.AJAX.RegisterScriptManager();
DotNetNuke.Framework.AJAX.
WrapUpdatePanelControl(this.pnlUpdate, true);
DotNetNuke.Framework.AJAX.
RegisterPostBackControl(this.btnSubmit);
}
}
catch (Exception exp)
{
//Step if ajax is not supported.
}
}

2 comments:

Anjum Rizwi said...

Your solution is not working. I am using dotnet nuke 5.0.

Sadique said...

Dear Anjum,

I used it in a live system and deployed it. It was working fine. But those were lower than DNN 5.