Saturday, June 25, 2011

Page_Load getting called twice

Hi All,

While working on one of my assignments past week I faced a strange problem. The problem was that my Page_Load event handler was getting called twice for apparently no reason. I was absolutely stumped. Then after a bit of trouble shooting and hit & trial, I found that the problem was a image tag.

My page gets post backed twice only in scenarios when source attribute's value of image control was rendering empty. So I just arranged a no image url in cases when there was no actual image url and got rid of my problem.

Similar problem I also faced a few months back, at that time I was working with link button. Then I was using link button for redirect user to some other page on link click. At that time I solved my problem by using hyperlink control in place of link button control.

Both these cases were, more or less magical for me ;)

I shared with you how I got my problem solved but if you know why was this problem occurring then kindly spare a few minutes to share it here. One more thing in both of these cases I was working on DNN.

Monday, June 20, 2011

Creating a DNN skin object

Hi All,

Below is a demonstration of how to create a DNN skin object. I’ll demonstrate this by creating a skin object that will display total number of users in your dnn site. Here we go:
Ø      Create a new project with template type “DotNetNuke Compiled Module”. Some other project type like class library project might also do but this one is easiest to start with.
Ø      I created a new project with name “CurrentUsersInfoSkinObject” and then cleaned it up by deleting all of the files from it, except below:
o       ViewCurrentUsersInfoSkinObject.ascx
o       ViewCurrentUsersInfoSkinObject.ascx.cs
o       App_LocalResources/ ViewCurrentUsersInfoSkinObject.ascx.resx
o       CurrentUsersInfoSkinObject.dnn
Ø      SkinObjects inherit from SkinObjectBase so change line
o       partial class ViewCurrentUsersInfoSkinObject : PortalModulebase
o       to
o       partial class ViewCurrentUsersInfoSkinObject : SkinObjectBase
Ø      Now add a literal control to ascx page, like below:
o       <asp:Literal ID="litUsersCount" runat="server" Mode="PassThrough" EnableViewState="false">asp:Literal>
o       pay attention on Mode and EnableViewState property.
Ø      Add one line to the resource file as below. This will serve as the base string to be shown in skin object.


Ø      Now place three lines of code in code behind file of view control.
o       string templateText = Localization.GetString("UsersCountDisplayTemplate", Localization.GetResourceFile(this, _myFileName));
o       templateText = templateText.Replace("[USERSCOUNT]", UserController.GetUsers(PortalSettings.PortalId).Count.ToString());
o       litUsersCount.Text = templateText;
o       In above three lines, first line reads resource file to get source string. Second line replaces placeholder [USERCOUNT] with number of users and set literal control to show this value.
Ø      Now just build this project, place dll in bin folder of your DNN installation.
Ø      Now place ascx and resource file in desktop modules folder, I placed these as shown in below image.

Ø      Now go to your dnn skin file. For me it was at,
Portals\_default\Skins\MinimalExtropy\ index leftmenu 1024.ascx
Ø      Add a line to register your newly added control. Like

<%@ Register TagPrefix="dnn" TagName="ViewCurrentUsersCount" src="~/DesktopModules/SkinObjects/ViewCurrentUsersInfoSkinObject.ascx" %>
Ø       Now add a line to place it at your desired place in skin. I placed it along with login control, like below:
<dnn:ViewCurrentUsersCount runat="server" id="UserCount" />
Ø      That’s all that you need to do to see your first skin object working.

About Me

My photo
Delhi, India
Fun, music, travel and nature loving, always smiling, computer addict!!