Handlers producing XML files, error when multiple parameters

Feb 25, 2008 at 3:11 AM
Hi everyone,

I have developed a SlideShow where both the Configuration.xml files and the Data.xml are created at runtime using handler (ashx) files.

As part of this code, I was passing a single URL parameter (called Album) which told the handlers which of my albums to load initially. The parameters are retrieved from the URL in the JavaScript of the aspx page, and then passed onto the handlers for generation of the XML files.

All was working well, until I tried to get a bit fancy today and add a second parameter so that I may further refine the way my slideshow works.

The Javascript is successfully extracting the 2 parameters (called Type and Album) from the URL and passing onto the config handler. The configuration handler retrieves both parameters succesfully, but when the config handler attempts to invoke the data handler it doesn't appear to be launching this handler and I receive a JavaScript error on the page stating that 'configuration' is null or not an object.

The part of the XML that is being generated in the configuration handler for the data component is as follows:
<dataProvider type="XmlDataProvider">
<option name="url" value="SlideShowDataHandler.ashx?Type=ProductsServices&Album=Pipe"/>

If I revert back to the single parameter, all seems to work fine again.

Anyone have any ideas of why this may be failing?

Many thanks (and I love the control, great work!!)
Feb 27, 2008 at 12:47 AM
No idea ;-) but just a quick thought (and its a bodge...) if the problem is only 1 param can be passed you could encode all params into one.

Sorry I dont speak asp but in php if I want to pass two values on an url (and also obscure values to the naked eye) I create a data structure:

$params = array ('Type'=>'ProductsServices', 'Album'=>'Pipe')

$enc = enc($params);
$url = "SlideShowDataHandler.ashx?id=$enc";

I can then decode the url later with a dec() function thats reverses the encoding process. You can throw in a bzcompress function in encode/decode as well if you want to pass a lot of data on the url and need to compress it to avoid hitting the browser url length limit.

function enc($x){
$x = serialize($x); // just like json
$x = base64_encode($x);
$x = str_replace("/","SlAsH",$x); // slashes, plus signs and equals signs can result from base64encode but not welcome on URL
$x = str_replace("+","PlUsS",$x);
$x = str_replace("=","EqUaL",$x);
return $x;

function dec($x){
$x = str_replace("SlAsH","/",$x);
$x = str_replace("PlUsS","+",$x);
$x = str_replace("EqUaL","=",$x);
$x = base64_decode($x);
$x = unserialize($x);
return $x;



p.s- Warning Way off topic ;-) I use these enc/dec functions for storing binary data in a database and obviously my string replacements aren't great as the patterns could appear randomly in data and are a performance hit on large objects. I've been using them for years and never had an issue where data was corrupted so apparently the chances of this sequence are very slim but.... Any ideas on a better way to encode data in safe fast manner?
Feb 27, 2008 at 1:59 AM
Edited Feb 27, 2008 at 2:01 AM
Hi sukerman, thanks for your reply. I had considered this, but hadn't gone as far as implementing it yet.

Your post did prompt me to revisit the problem though and I found the (glaringly obvious) mistake...

Where I was generating the XML line:
<option name="url" value="SlideShowDataHandler.ashx?Type=ProductsServices&Album=Pipe"/>

in my asmx code, I was using the expression:
sb.Append("<option name=\"url\" value=\"SlideShowDataHandler.ashx?Type=" + Type + "&Album=" + Album + "\"/>");

instead of:
sb.Append("<option name=\"url\" value=\"SlideShowDataHandler.ashx?Type=" + Type + "&amp;Album=" + Album + "\"/>");

And of course using the & on its own rather than &amp; was causing the grief...