1

I'm attempting to take a basic serializable object that's held within a seriazable dictionary and pass it to a javascript function that will generate a modal with that information. The object has a few string variables, nothing complicated.

Here's the object I'm passing in:

[Serializable]
public class Details
{
    public Details() {}

    public string ID { get; set; }
    public string Name { get; set; }
}

I set the strings to their appropriate values, and then attempt to create a link that calls a javascript modal (the ID is calling the appropriate:

protected string WriteDetailsLink(object ID)
{
    string results = "";

    JavaScriptSerializer jss = new JavaScriptSerializer();
    results += "showDetailsModal(" + jss.Serialize(dictionaryList[ID.ToString()]) + "); return false;";

    return results;
}

And the html link itself on the aspx page:

<a id='detailsDialog' onclick="<%# WriteDetailsLink( Eval( "ID" )) %>">Details</a>

And the javascript function for the modal, currently displaying nothing:

function showDetailsModal(Details) {



    $('#DetailsModal_dialog').dialog(
    {
        modal: true,
        //height: 500,
        width: 600,
        resizable: false,
        draggable: false,
        open: function () {

        },
        close: function(event, ui) {}

    });
}

Everything works fine, the ID gets passed along and when I inspect the link after running it looks like this:

<a id='detailsDialog' onclick="showDetailsModal({"ID":"40662463","Name":"72485-3"}); return false;">Details</a>

And it looks to be the same format as code elsewhere in our project, but I keep getting a

"Uncaught SyntaxError: Unexpected token ;"

error. I can't for the life of me figure out what's going wrong. If I pass just a string to the modal function, it works. I really don't want to have to send a bunch of clumsy strings and have to parse through them manually.


UPDATE:

Yup, it was the quotes around the link that was causing the issue. But now I'm encountering a new problem:

I've got a div setup for the modal and I'm attempting to parse out the name to insert into it, here's the new function (notice Name is now BatchName):

function showBatchDetailsModal(groupDetails) {

    var tmpData = jQuery.parseJSON(groupDetails);

    $('#DetailsModal_dialog').dialog(
    {
        modal: true,
        //height: 500,
        width: 600,
        resizable: false,
        draggable: false,
        open: function () {
            $('#detailsName').text(tmpData.BatchName);
        },
        close: function(event, ui) {}

    });
}

I'm getting

"Uncaught SyntaxError: Unexpected token o " in jquery.min.js

1
  • 1
    Looks like the quotes are messed up to me ! Commented Apr 1, 2014 at 20:33

2 Answers 2

2

Change your onclick to use single quotes to wrap the function call:

onclick='<%# WriteDetailsLink( Eval( "ID" )) %>'
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, that was it, thank you very much! But I've since run into a new issue, I've updated my original question.
0

Your code should be he following

function showBatchDetailsModal(groupDetails) {

    var tmpData = groupDetails; // jQuery.parseJSON(groupDetails);
    //Don't need to parse it into json. as its already parsed.

    $('#DetailsModal_dialog').dialog(
    {
        modal: true,
        //height: 500,
        width: 600,
        resizable: false,
        draggable: false,
        open: function () {
            $('#detailsName').val(tmpData.BatchName); //<--- .text(...) is changed to .val(...)
            //If val(...) doesn't work use .text(...)
        },
        close: function(event, ui) {}

    });
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.