Sunday, October 11, 2009

Two DNN issues I had to fight with this weekend

Had to really weird DotNetNuke (DNN) issues to work through that had me working most of this weekend.

The first one had to do with what manifested as a javascript error - “this.container.parentnode is null or not an object”

The issue turned out to be because I was using the JQuery javascript library. The library provides the $ macro as a shortcut to jQuery. But DNN already uses the $ macro, which causes issues. Fortunately, the fix is simple. Call the following method in a script block in the head of the document:


This stops jQuery from trying to use the $ alias. Which means that you cannot use the $ alias to select DOM objects. Instead, whereever you use $ to work with JQuery, you need to directly reference the library using “jQuery”.

eg: $(document) becomes jQuery(document)

The second issue had to do with ViewState and a user control that was loaded using LoadControl

In other words, the user-control was being loaded dynamically using the LoadControl module. For the most part, the control was working. What was not working was the ListBox was not keeping its SelectedItem value, after I had selected an item in the ListBox and then clicked a button that caused a post-back.

After running around in many many circles, the thought that I have is that its because the ViewState is not working correctly. (The user-control works fine if I directly reference the user-control in a aspx page. The problem only occurs when the user-control is added dynamically using the LoadControl module).

The way I worked around this issue is that whenever I added items to the ListBox, I stored the items to the Session object. I then over-rode the OnInit method, and use the items in the Session object to load into the ListBox. The reason that I think this solution works is that the view-state is not working correctly and so I am giving the control a helping hand by filling it with the values that it should have after a post-back. All other events occur after the OnInit method has been called, allowing the SelectedItem to be correctly set.

No comments: