Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
985
Passing xml with templating to a javascript function
posted

We managed to bind an object to the grid. One of the properties of the object is a string that contains xml. This xml contains some detail information that the users might want to view. With templating we managed to show an icon in case the template is present, like this:

<td> {{if ${Template} !=""None""}} <input type=""image"" src=""../Resources/MagnifyingGlass.png"" align=""left"" onclick=""popUp(${Template});""/> {{/if}} </td>

In this case ${Template} is the string that contains the xml.

This does work fine in Firefox. When the image gets pressed the javascript gets executed and details are shown to the user. However in IE we get the exclamation sign stating that the page loaded with errors. While at first glance everything seems to have loaded with no problems we are unable to click the button that will show us the detail information.

When I place an imagebutton like the one on the grid directly on the page there is no problem with the execution, so my guess is that there is something up with the combination of the xml, the row templating and IE. Do you have any clue what might be up here?

 

PS.

The xml that we use for testing looks like this:

<Template>
  <Description>This is a test</Description>
  <Field>
    <Label>TestLabel</Label>
    <Content>This is a test</Content>
  </Field>
</Template>

Parents
  • 6279
    posted

    Hi,

    Truth be told, I'm surprised that you were able get this scenario to work - it's not a simple one.
    First off, can you please click on the yellow exclamation mark in IE - it will bring up a popup window with the error that has occurred on the page?

    Second, can you please provide us with a sample where we can reproduce the scenario (HTML if possible)?

    Given the details you provided (the template for the Template cell and its value) - thanks for those! - I couldn't get my HTML sample to work under Firefox and under IE I got the following error when clicking on the image: 

    So I decided that as an alternative to XML I could use JSON, but that required a few tweaks as well.
    As a first step, I am using a 3rd party JavaScript library that lets me convert XML to JSON (http://code.google.com/p/x2js/).

    Second, ended up putting the value of the Template object into a data-value attribute and I assigned a click handler for the image using jQuery
    The cool thing is that using the browser-embedded JSON.parse() and JSON.stringify() functions I am able to switch the data from a string to an object and vice versa.

    Hope the sample I've attached to this reply will be of use to you.

    Cheers!
    Borislav 

    t69711.zip
Reply Children