Wednesday, February 25, 2009

How to use DotNetNuke Module Control in WebParts

Some days ago i was working on an assignment and was wondering how we can use a DotNetNuke module control in Web Part control. I developed a dotnetnuke module's view type of control which shows top 10 guest book comments and its working properly in dotnetnuke. Now the questions is, how can I use the same control in webparts framework also?

Well I've started some research and started with some basics. DotNetNuke module controls are inherited from DotNetNuke.Entities.Modules.PortalModuleBase. They can then import various DotNetNuke interfaces for plugable features like IActionable, IModuleListener, IModuleCommunicator etc. To use a control as a webpart control, it must inherit IWebPart interface and implement it. So I just do that:

#region IWebPart Members
private string _ImageUrl;
private string _title;
private string _description;
private string _subtitle;
private string _titleIconImageUrl;
private string _titleUrl;
public string CatalogIconImageUrl
{
get
{
return _ImageUrl;
}
set
{
_ImageUrl = value;
}
}

public string Description
{
get
{
return _description;
}
set
{
_description = value;
}
}

public string Subtitle
{
get { return _subtitle; }
}

public string Title
{
get
{
return _title;
}
set
{
_title = value;
}
}

public string TitleIconImageUrl
{
get
{
return _titleIconImageUrl;
}
set
{
_titleIconImageUrl = value;
}
}

public string TitleUrl
{
get
{
return _titleUrl;
}
set
{
_titleUrl = value;
}
}

#endregion

After that, I started using it on my webpart's page. I just register that control and use it under CatalogZone control's WebPartTemplate.

My module is working well as well as my webpart control is also working cool. Anybody who want to do this can simply learn the basics for implementing webparts, and for that, just go through the walkthroughs of msdn for webparts and then try my trick.

Friday, February 20, 2009

DotNetNuke - Clearing cache dynamically or programmaticaly

Perfomance is a key requirement for every application, and so does it is for DotNetNuke web applications also. DotNetnuke uses data caching as an inbuilt approach and provides a provider for cache also. It always adds good perfomance gain by setting the proper cache value and cache policy to you dotnetnuke web application. But there are times when you need to clear the cache of the application. If you are a host or admin and you want to manage it from the from end, you can go to :
Host - Host Settings - Advance Settings - Perfomance Settings
You can find a clear cache button there which will help you clearing cache. But there are times when this is not logical. For intance if you are allowing a user to choose a new skin from the list, when user clicks and applies a new skin, at that time you have to clear the cache manually, otherwise changes will not reflect properly.

DotNetNuke.Common.Utilities.DataCache is a class which will help you clearing cache at various occations like I discussed above. In our scenerio, we have to clear portal cache and we can do that by calling
DotNetNuke.Common.Utilities.DataCache.ClearPortalCache(PortalId, false);
And its as simple as that. There are lots of other functions to clear cache starting from clear, like ClearModuleCache or ClearModulePermissionCache. You can use them as and when required.
Hope that helps

DotNetNuke - Reset LoginTabId of a portal

Hey friends,
lots of time in DotNetNuke development, we change the default LoginTabId from site settings for portal 0 and forget to add the login module in the newly added tab. That will cause you into the problem. You can reset it by executing the following t-sql script:

update Update {databaseOwner}{objectQualifier}Portals
Set
LoginTabId=NULL
Where PortalId=@portalid
-- by default if its in portal 0 with no qualifier then you can execute
--update Update dbo.Portals
--Set
-- LoginTabId=NULL
--Where PortalId=0

JavaScript Validation: Alphanumeric and underscore only


//add this to textbox :onkeypress="validate(event);"
// validates and don't allow typing characters other than a-z,A-Z, 0-9 and _
function validatePortalName(e)
{
if(window.event) // IE
keynum = e.keyCode;
else if(e.which) // Netscape/Firefox/Opera
keynum = e.which;
return ((keynum >= 97 && keynum <=122)(keynum >= 65 && keynum <=90)(keynum>=48 && keynum<=57) keynum==95);
}

Note: code is tested in ie7 and mozilla firefox 3.0.6. Please test in the borwser you target before using it in production. regards

Thursday, February 19, 2009

converting JQuery samples into ASP.NET - Coda-Slider

JQuery is becoming popular now a days and there are lots and lots of new samples, plugings and small utilities are available across the web. Apart from the too many demos of plugins and UI, people are building nice looking samples which can be a plugable add on to your website. When I was browsing through google for JQuery samples, I see Coda-Slider, an HTML, CSS, JQuery sample that looks like a tab at first signt but when you change the tab, and actually it is, but it changes the slides stylishly.

After getting that, what i was doing is, trying to create and xml for the slides and get it working on asp.net with c# backend. So downloaded the files and just started converting it. Here is what i've done.
  • I assumed i need to dislpay different product slides on the home page of the site, so I have created the xml and placed some dummy product data into it.
  • Used sample html, and pasted all the required js and css into root directory.
  • Added the requeired code in the aspx file and used repeater for the slides
  • And that's it, i got it working.

I just name it a product slider. There are lots of improvements that can be done on it, but before that I am trying to implement it in DotNetNuke. From this code, anyone can create a module called ProductSlider, and just adjust the paths of js and renaming the css with modules.css will work.

You can download Coda-Slider from its website. You can aslo donwload asp.net version of it which i named Product Slider.

Please write back if you have troubles with implementation of dotnetnuke module.

Tuesday, February 10, 2009

Free DotNetNuke Skin : Nature


Free oswd.org template Nature is converted into a dotnetnuke skin.
Here is a quick summary of the skin:
  • Validate XHTML 1.0 Strict
  • Only root level menu its are having styles
  • Dnn logo and search, login and username skin object styles can be improved by adding appropriate styles.
You are free to download and use this skin under creative common licence. You can download the skin from here

Friday, February 6, 2009

Modalpopup in DotNetNuke

Introduction
Web application interfaces are becaming more and more advanced and we see modal dialogs in many popular websites. One of the best social bookmarking site Digg uses modal popup for log In. As a developer, when you want to implement modal popups, you should know abcs of it. I've written an article about creating a simple modal popup in HTML4 after learning some basics of html, css and javascript. After almost a month, I was looking at the search keywords and dotnetnuke forums, and I have come to know that users want to implement modal popup in dotnetnuke also. So I just thought it would help to just guide those users.
Which Doctype are you using?
Well If you are using dotnetnuke 4.x and want to implement modal popup, first thing you should check is, which doctype your sking is using. If you don't know that, its really simple to know that. Just run your application in browser, and from View > View Source look at the very first line of browser source, it must be showing a doctype tag.
Implement in HTML4
Once you know the doctype tag, if you are using HTML4 doctype, then you can use my previous article which shows how you can create modal popup in HTML4. That article focus on javascript and css code to implement a simple modal popup dialog in your web application. You can change that modal background color and design your own popup design using that. The javascript code can be used as it is except you need to change the control ids according to your code if you are not using same ids as i have used in my html code give in that article.
Implement in XHTML
If you are using XHTML strict or transitional doctype then you can Ajax Control Toolkit's modal popup extender control. If you want to use ajax control toolkit controls in dotnetnuke, you have to learn how to do that, and this article can help you to quickly get familiar with that.
Implement using jQuery
Another way to implement modal popup in dotnetnuke for XHTML doctype is to use jQuery. You can easily get a modal popup plugin written in jQuery which you can use in dotnetnuke also. Here is an example to get it from google search.

If you are having problems referencing jQuery js and other js files, you can use ModulePath and SkinPath variables, to help browsers find right path in dotnetnuke application. If you are adding jQuery at module level and you have placed the jquery js and plugin js in module's directory, then used prefix like following to make sure browser will get the js properly.

<script src="<%=ModulePath%>jquery.js" type="text/javascript" />

and in same way if you using jquery at skin level then you can use SkinPath variable.

Hope you enjoyed the summary about creating a modal popup in dotnetnuke. Please write me your feedback if you need code along with this.
Happy coding :)

Thursday, February 5, 2009

Google Map Asp.Net Control

Hey friends,
Google's Map API is one of the well known apis for mapping. Integrating that api into an asp.net web applications is a challenging working and we were googling around the web for getting an asp.net control for google map api.

First of all, we implemented javascript based apis for google maps. That was working nicely. The only problem we found that map is loading after all of the content of the page is loaded. The obvious reason behind that is, we are using javascript. So we thought we can improve the code by making a server side implementation of the code.

There are lots and lots of results on the web and most of them are not usable for me, either they are not working or they are implemented in framework 3.5 and we need for framework 2.0.

After juggling with downloading codes and testing them around, finally we got a working example. here is a link: http://www.codeproject.com/KB/webforms/Google-Maps-User-Control.aspx. I hope this will help when you need to implement your code, and you will not have to go for google it again and again.
Happy coding :)

Popular Posts