Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Using ajax in DotNetNuke

0.00/5 (No votes)
9 Aug 2010 1  
Article describes how to load data from server and show results on DotNetNuke page using AJAX.IntroductionThere are many nice javascript

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

Article describes how to load data from server and show results on DotNetNuke page using AJAX.

Introduction

There are many nice javascript controls and libraries that you could use within your DotNetNuke site but you are not. This is often because they need to load some data from server in form of text, JSON, XML, etc. And after user made some manipulations you probably want to update some data in the database, but again without page reload. But how data can be delivered to the client-side script? Using Visual Studio leads to huge overhead: you need a test environment, you must plan deployment, etc. If you have a small site and little budget you probably won't be happy with this. But there is a way to do it rapidly without any compilation, deployment, test environment and other stuff.

There are 3 steps to be done here:

  • Write SQL code
  • Create server-side code that formats data and sends it to the client
  • Write a client-side code that initiate the process and send data to the UI controls.

All this stuff can be easily done using DotNetNuke browser-based development environment - XsltDb. Here I show you 2 ways of delivering data from server to client: by using AJAX and by providing URL.

Using javascript function to access server

This is what we want to have on client:

   getSomeDataFromServer(a,b,c, function(downloadedData){
someControl.data = downloadedData;
});

Some function sends some parameters to the server and calls a callback when done. To create such a function I use XsltDb. Put a new XsltDb module on a page where you need this javascript function and write following code into it:

  ##handler: getUsers(searchKey)
<xsl:copy-of select="mdo:sql('
select UserID, DisplayName from {databaseOwner}[{objectQualifier}Users]
where Username like @searchKey
', 'user', '@searchKey', mdo:request('searchKey'))"/>

That'all ! Three step mentioned above are completed.  Attention! This module must be a super module (checker above the code editor) as it accesses database directly. This function searches for users by DisplayName The usage is:

  alert(getUsers('%bu%'));  /* Synchronous */
getUsers('%bu%', function(users){ /* Asynchronous */
alert(users);
});

Creating an URL that returns some data as XML

Again, put a new XsltDb module on a page. Paste the following code and check "super module" option:

<xsl:if test="mdo:request('service')">
<xsl:copy-of select="mdo:sql('
select UserID, DisplayName from {databaseOwner}[{objectQualifier}Users]
where Username like @searchKey
', 'user', '@searchKey', mdo:request('searchKey'))"/>
</xsl:if>

Fill alias field above configuration as users. After that you can use the service as follows:

  $.get('/DesktopModules/XsltDb/ws.aspx?service=users&searchKey='
+ escape('%bu%'), function(xml){
alert((new XMLSerializer()).serializeToString(xml));
});

As you see, AJAX-ing in DotNetNuke is quite simple!

Tools used

Tools used for this article:


 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here