Mini Post – DotNetNuke and web.config problems

I could have Twittered this but I wanted to put it here: Every now and again I find myself refreshing my developer’s copy of my project on my local computer from source control.

The way I have source control is primitive and probably incorrect. I tend to save ALL of my project (DotNetNuke included) into source control, so when I get a clean setup, I can basically run it out of the box.

This particular time, I was working with a different database than I normally do. Because of this, my source control wrote over my web.config and copied the wrong database settings, which resulted in the web.config pointing to a no-longer existing database.

When I loaded up my website, I was greeted with the installation wizard from DotNetNuke. “Okay,” I thought, “Perhaps I forgot to update this particular database with the new DNN version.” I clicked on next a few times and realized it was just the wrong database being referenced. I changed the web.config to be the correct database and credentials and all was well…

Or was it?

I loaded up my project and I was getting rather unhelpful “I need to put a ScriptManager on the page in order to use AJAX.net” error. I just couldn’t figure it out! It worked before! Long story short, the DNN install wizard messed around with the web.config and broke a few things configured specifically to my install. Once I pulled up an older web.config, everything worked perfectly.

This wasted about 2 hours of my time (which I don’t really have) and was easily avoidable if I was paying attention.

Lesson learned: Always be methodical with processes which you perform regularly.  If something strange goes wrong within the process, it probably doesn’t belong and should be approached very, VERY carefully.

Opening to a New Window – Why Isn’t the Target Attribute a Valid Tag?

Ever since I was a young web developer going through college, it has been drilled into me to be standards compliant when developing for the web.  In fact, it went as far as being 20% of your grade just to be XHTML 1.0 Strict standards compliance.

Just to be clear, I am talking about XHTML 1.0 Strict.  Transitional, while it has its uses, doesn’t capture the essence and spirit of why we want to be standards compliant.  Creating your web sites to be standards compliant is something as web developers we should strive for.  It promotes standardization of markup, it helps to separate layout from content, and it creates the ability for all modern browsers to display the site same way… sort of.

One thing that really gripes me is the target attribute for the <a> tag.  This was marked as obsolete, and in the strict specifications, it’s invalid.  Why is this the case?  It’s very helpful,  unobtrusive, and works really well with tabbed browsers.  I can understand every other valid XHTML ‘no-no’ such as not using align attributes or a center tag, just this one just kind of escapes me.

<a href="http://www.google.com" target="_blank">Why is this invalid?</a>

So why is it invalid? As far as I can tell, it’s because we shouldn’t assume it is what the user intended and that it should be left up to the user.  I really hate this explanation.  It makes me think whomever thinks it has never dealt with a real world user.  Most people outside of the technological world are not savvy enough to right-click and open a page in a new window.  For us that do know how to do it, it’s actually quite annoying.  Besides, when I link to a webpage outside of my domain, how often would we want the user to navigate away? It is not very user interface friendly in my opinion.

Another reason is the page loses the effectiveness of the back button.  Okay, I can buy this, but it’s packed neatly on a new tab on all new modern browsers.  It’s easy to navigate back to the original site.

A last reason I can discover is because of screen clutter.  This is becoming a moot point due to the fact that almost every popular browser uses tabs rather than opening a new window.  In fact, the only browser which doesn’t utilize tabs is IE6, and it’s popularity is quickly dying.

The standards compliant solution: Use Javascript. Bah!  That’s just something else I have to test.  target=”_blank” works fine in all cases.  Using Javascript to do something the browser does natively feels silly.  I know the code is pretty compact and with jQuery you could literally do it in one line, it’s not nearly as clean and understandable as target.

My user experience friendly solution: In order to appease the target-hating standards compliant gods, my solution is this:  Provide a setting on the top of the page which asks “Open all links in a new window” and “Open all links in the current window.”  This way, you allow the user to decide how it works, it’s standards compliant, and it’s fairly simple to implement.

Perhaps help is on the way. Doing some research on the topic, I came across the spec document for CSS3 Hyperlink Presentation (yes, this opens in a new window!) which describes using CSS to determine target parameters.  I can easily get on board with that!  Hopefully we can see CSS3 implemented across all major browsers in the not-to-distant future.

In Conclusion: I will still be using target=”_blank” to pop up new tabs on my blog.  The blog is validated in Transitional anyway.  My belief is that any hyperlink in a blog post will be clicked on to allow further reading of the topic.  That is the experience I want to provide for my readers.

DotNetNuke Settings Issue: Truncated Data

DotNetNuke is great.  It has a great established core, along with a fairly straight forward process for developing extended modules.  You can use the already established DotNetNuke settings framework in order to facilitate settings for each instance of your own module.

We have a unique install in which we have central data that is shared by many custom modules.  I needed a way to have specific settings per portal, so I built a custom settings library.  I also wanted to be able to override these settings so I built in an XML parser to do so.

I found out the hard way that the settings table has an nvarchar size of 2000.  This almost never affected us, since the XML is generally smaller than 2000 characters, but I had one setting that went over.  It messed up my xml, and broke my module.

My immediate fix was to change the core database.  I made the settings to be nvarchar(MAX), and set up the add and update stored procedures to accomodate them.

I believe the best way to fix the issue without changing the core is to create another table, which either has a text type or a varchar(MAX) as the value.

Visible=”false” vs. display:none;

I find that when you are a new programmer or a programmer using a technology for the first time, there are a few gotchas’ that could make or break your learning experience.  When learning the power of .NET, especially after developing primarily in PHP,  the differences between Visible=”false” and display:none; was a huge gotcha for me.   I figured I’d help you realize what exactly the differences are and when you should use one or the other.  Take the source code:

<asp:Panel style="display:none;">
Error Message
</asp:Panel>

and

<asp:Panel Visible="false">
Error Message
</asp:Panel>

If you were to render both of these, you would see the screen the same thing: nothing.  However, if you look at the source of both of them, you will realize that the former will appear in the source but the latter will not.  That’s because in the first example, command display:none is CSS, which is client-side and in the second example, “Visible” is a server-side. On more complex pages, they are very much different.

When to use the display:none;

Let’s say you have a form in which you want to hide some elements of it, entirely for user experience (perhaps you want to hide the address field in case it is optional). If you used Visible = false, the button would have to postback, run back-end code to change the visible=”true” and render back to the browser the entire page. This exercise taxes the server, and is not an optimal user experience. It would be nicer to open the box via javascript.  if you used style:none; on an element, you would just need to run display:block; in order to show it.

When to use Visible=”false”

If you will never need access to the element via Javascript, then this is the better function to use.  This way, the element will never get rendered, and therefore keep the precious bandwidth of your pages to a minimum.  Also, maybe you want to run server-side code when you restore the address field. In this case, it is better to use Visible=”false”

I hope this helps you better understand the differences between the two types of hiding elements in .NET.  If you have any questions, let me know!