Archive

Archive for the ‘Development’ Category

Using the DotNetNuke Profile Photo in a Custom Module

March 12th, 2011

no_avatar dnnprofilephoto

 private string GetUserPhotoUrl(UserInfo user)
 {
        if (user.Profile.Photo == null || user.Profile.Photo == "-1")
            return user.Profile.PhotoURL;
        else
            return VirtualPathUtility.ToAbsolute("~/LinkClick.aspx") + "?fileticket=" + user.Profile.Photo;
 }

An anonymous user or a user without a profile photo will always get the default ‘no_avatar.gif’ image.

Development, DotNetNuke

DotNetNuke MVP Module Development: Tip #2 Disable AutoDataBind

February 24th, 2011

In DotNetNuke MVP Module Development: Tip #1 The AutoDataBind Property I suggested to use AutoDatBind to automatically bind up the user control.  However, there are times when no binding should occur.  For example, when a ‘Cancel’ button is clicked the view should not be bound.  AutoDataBind should be disabled when no model is need.

protected void cmdCancel_Click(object sender, EventArgs e)
{
    try
    {
        AutoDataBind = false;
        OnCancel();
    }
    catch (Exception exc)
    {
        Exceptions.ProcessModuleLoadException(this, exc);
    }
}

Development, DotNetNuke, Web Development , , ,

Quick Tip: Use JQuery to submit a TextBox.

February 24th, 2011

imageSubmitting a search box when <Enter> is pressed is a nice usability feature to provide.  Unfortunately, ASP.NET Web Forms and it’s requirement for a single <form> tag breaks this expected behavior when there is more than one submit button on the page.   This can be easily fixed with a JavaScript and JQuery.   Listening to the keydown event on the TextBox the ‘Go’ submit button can be triggered when <Enter> is pressed.

jQuery("#searchTextBox").keydown(function (event) {
    if (event.keyCode && event.keyCode == '13') {
        jQuery("#searchButton").click();
        return false;
    } else {
        return true;
    }
});

Development , ,

DotNetNuke MVP Module Development: Tip #1 The AutoDataBind Property

December 24th, 2010

The DotNetNuke.Web.Mvp.ModuleViewBase sets a property called ‘AutoDataBind = true’.  As a result the DataBind() method for the page is always called in the Page_PreRenderComplete event. 

If you use the following familiar snippet of code you find that your controls will be data bound twice.  Once when your code calls DataBind() and a second time when it is called during the Page_PreRenderComplete event.

ddlStatus.DataSource = Model.StatusList;
ddlStatus.DataBind();

Here is an example of how to properly bind a DropDownList for an MVP based module.

<asp:DropDownList ID="ddlStatus" runat="server"
    DataSource='<%#Model.StatusList%>'
    DataTextField="Description"
    DataValueField="Id"    SelectedValue='<%#Model.Post.PostStatus %>'>
</asp:DropDownList>

It is important to point out again that you should not call ddlStatus.DataBind() from the code behind.  Calling this is a waste because the AutoDataBind property is going to force everything to rebind again during Page_PreRenderComplete.

Development, DotNetNuke

Offsetting the time zone in MS SQL 2005

August 10th, 2010

I needed to offset the current time in MS SQL 2005 for a quick fix. I wanted to make sure the solution would not have to be maintained when daylight savings time changed. Taking the difference between the GETUTCDATE() and GETDATE() functions will generate the server’s current time zone offset from UTC time.

DECLARE @timezoneOffset INT
SELECT @timezoneOffset = (DATEDIFF(hh,GETDATE(),GETUTCDATE())) * -1;
SELECT DATEADD(hh, @timezoneOffset, GETUTCDATE()), GETDATE()

Development ,