Tuesday, 19 May 2009

TinyMCE ListBox Plugin for Merge Tags

Well, today I finally managed to cobble together the following solution for a problem I had whereby I wanted a plugin for TinyMCE whereby I could select a value from a drop down / listbox, and have it inserted into TinyMCE.

So here's how I did it:

First define a javascript array BEFORE initialising the TinyMCE editor. This allows you to create this array server side if you want (by writing a response stream declaring it if necessary), or allows you to control it per page. E.g:

var arrUserTags = new Array('{{Name}}','{{Address}}','{{Company}}');


I created a new plugin in tiny_mce/plugins/usertags/editor_plugin.js as follows:


(function() {
tinymce.create('tinymce.plugins.usertags', {
init : function(ed, url) {
},
createControl: function(n, cm) {
switch (n) {
case 'usertags':
var mlb = cm.createListBox('usertags', {
title : 'Insert details ',
onselect : function(v) {
tinyMCE.activeEditor.selection.setContent(v);
}
});

//The array arrUserTags, must be defined before the editor is added!!! Or if you prefer, just ignore the array idea, and just do multiple mlb.add() statements.
for(i=0;i

This you can then register as a plugin in tinymce.

CompareValidator doesn't compare numeric amounts correctly

Well at least that is what I thought today!

I had a compare validator set on two text boxes that were used to enter monetary amounts. The validator was to ensure that box B was greater than Box A.

In this scenario, it worked:

Box A = 100, Box B = 200 = Fine

But...

Box A = 500, Box B = 1000 = Invalid

Why? Because I hadn't set the TYPE attribute of the validator to CURRENCY

D'oh!

Thursday, 14 May 2009

TinyMCE UpdatePanel Javascript errors

I have spent days on this one, and it took myself and a colleague both working on it to find a solution that actually worked!

Here's the scenario.... you want to use TinyMCE, and have it working in an UpdatePanel. It sounds simple enough.

What I did was add the TinyMCE editor script, setup my tinyMCE.init() method, and hey presto, I got my editors. I set my code behind for my save button, and it fired fine when pressed, however, the editor disappeared! So, I moved my init function into the code behind, and registered it with the scriptmanager.registerclientscript method. This was fine, and when svaing my content, the editor did not disappear anymore - however, when I clicked the save button for a second time, I got a javascript error on the editor trying to access it's content.

The specific part of the javascript from tiny_mce.js was erroring on "return this.bodyElementthis.getDoc().body"

Anyway, I searched through many examples of how to solve this, including remove the editors before performing the postback, and eventually found a downloadable example that worked:

http://codeodyssey.com/archive/2007/7/18/updatepanel-tinymce-demo-with-project-zip-file

However, when I tried to use this in my application, with TinyMCE version 3.2.3, it didn't work. I copied over the version from this download, and then it seemed to fix the problem - but I lost some of the TinyMCE functionality!

Eventually, my colleague stumbled upon this absoluetly brilliant .NET extender, that handles everything for you, and allows you customise each editor independantly:

http://weblogs.asp.net/cjdevos/archive/2008/06/19/ajax-extender-for-tinymce-continued.aspx

So, if your having problems with TinyMCE and updatepanels - download it and use it!

Wednesday, 15 April 2009

Math.Log in VBScript

Today I was working on an old Classic ASP project, and I was converting some JavaScript code to ASP.

Part of the code used the JavaScript Math.Pow function, e.g. Math.Pow(4,3), and I needed to do this in classic ASP.

I found that the ^ operator in VBScript does this, but it wasn't easy to transpose into my code, so I just added the following function to the page:

FUNCTION Pow(val, val2)
Pow = val ^ val2
END FUNCTION

Added called it as needed, e.g. Pow(4,3)

Thursday, 12 February 2009

SWFObject and LightBox2 - IE Errors

Today a colleague of mine had a problem whereby he was trying to use LightBox 2 in a webpage, but on that page, we received the "Internet explorer cannot open the internet site XXX Operation Aborted" message, and the page doesn't load.

After a lot of debugging, nothing was apparent, and it didn't happen in Firefox.

After reading around a bit, it seems that IE has a few issues with DOM commands, and as such, the SWFObject and Lightbox2 scripts both try to access the DOM at the same time.

So, all I did was move the SWFObject script to the foot of the page, and keep the div that it is written into in its normal place.

Sorted.

Monday, 5 January 2009

Wireless stops working after XP SP3 installation

A friend brought her laptop round to mine yesterday, as after xp had done an update and installed xp sp3, the wireless was showing as connected, but no page would load. When wired in, all was fine.

I tried connecting it to my WPA enabled network, and all was fine. After googlin the problem, I found that there were some issues that some people had had with WPA after xp sp3, but not with WEP - in fact, they were recommending switching to WEP (Not a good idea).

Anyway, I did the alternative, changed their laptop and belkin router over to wpa2 psk, and it's fine now!

Wednesday, 17 December 2008

Javascript parseInt, parseFloat, decide on data type

I was facing an issue today whereby I need to accept a value from an input control, but not knowing what it contained - i.e. a number, a floating point number (decimal) or a string, but I needed to perform maths on it.

With some help of some friends over at forums.asp.net, I came up with the following. You pass it your value, and it will send back the right data type to use on mathematical operations like "+" which normally concatenates strings instead of adding numbers as strings.


function parseValues(aValue)
{
if(isNaN(aValue))
{
return aValue;
}
else
{
if(aValue.indexOf(".")>0)
{
return parseFloat(aValue);
}
else
{
return parseInt(aValue);
}
}
}