Javascript eval String + variable
<p>I have a piece of javascript code evaluated at runtime, with the &lt;%= %> syntax...</p>

<p>Now, inside the &lt;%= %>, instead of a hard coded string, i'd like to have the value stored in a variable... How can I do this?</p>

<p>This is the function:</p>

<pre><code>function updateDescriptionLabel(msgToParse, dataColumn, TextBoxID) {
    var myData = JSON.parse(msgToParse.d);
    alert(msgToParse);
    alert(dataColumn);
    alert(TextBoxID);

    // this is the explicit call, it's ok
    $('#' + '&lt;%= this.TextBoxDES_MACCHINA.ClientID  %&gt;').val($.trim(myData["DescrMacchina"]));

    // NOW i want to make the call by using the variable value
    var txtDes = TextBoxID;

    $('#' + '&lt;%= this.' + txtDes.toString() + '.ClientID %&gt;').val($.trim(myData["DescrMacch"]));

    // BUT i get the error: Too many characters in character literal
}
</code></pre>

<p>============== EDIT ===============</p>

<p>I have a bunch of TextBoxID that, on lost focus, get a get a value from database, and display it on the appropriate TextBoxDESCRIPTION related to the ID...
But I have to duplicate the code for each TextBox, so I'd like to generalize it...</p>

<p>I post the entire code.</p>

<pre><code> &lt;script language="javascript" type="text/javascript"&gt;



    /* ==&gt; JSON  */

    //Ajax Request
    function SendAjaxRequest(urlMethod, jsonData, returnFunction) {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: urlMethod,
            data: jsonData,
            dataType: "json",
            success: function (msg) {
                // Do something interesting here.
                if (msg != null) {
                    returnFunction(msg);
                }
            },
            error: function (xhr, status, error) {
                // Boil the ASP.NET AJAX error down to JSON.
                var err = eval("(" + xhr.responseText + ")");

                // Display the specific error raised by the server
                alert(err.Message);
            }
        });
    }

    // I'd like to generalize it ...
    function SendComplexAjaxRequest(urlMethod, jsonData, returnFunction, dataColumn, TextBoxID) {
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: urlMethod,
            data: jsonData,
            dataType: "json",
            success: function (msg) {
                // Do something interesting here.
                if (msg != null) {
                    returnFunction(msg, dataColumn, TextBoxID);
                }
            },
            error: function (xhr, status, error) {
                // Boil the ASP.NET AJAX error down to JSON.
                var err = eval("(" + xhr.responseText + ")");

                // Display the specific error raised by the server
                alert(err.Message);
            }
        });
    }




// ONE function for each textBox
    function callUpdateGuastoAttributes(code) {
        var urlMethod = '&lt;% = ResolveClientUrl("~/Services/ws_Attributes.asmx/OdLGetMacchinaAttributes") %&gt;';
        var jsonData = "{'COD_MACCHINA':'" + code + "'}";
        var successFunction = updateLabelsGuastoAttributs;
        SendAjaxRequest(urlMethod, jsonData, successFunction);
    }

    function callUpdateCausaGuastoAttributes(code) {
        var urlMethod = '&lt;% = ResolveClientUrl("~/Services/ws_Attributes.asmx/OdLGetMacchinaAttributes") %&gt;';
        var jsonData = "{'COD_MACCHINA':'" + code + "'}";
        var successFunction = updateLabelsCausaGuastoAttributs;
        SendAjaxRequest(urlMethod, jsonData, successFunction);
    }


// I can have only one function:
    function callUpdateMacchinaAttributes(code) {
        var urlMethod = '&lt;% = ResolveClientUrl("~/Services/ws_Attributes.asmx/OdLGetMacchinaAttributes") %&gt;';
        var jsonData = "{'COD_MACCHINA':'" + code + "'}";
        var successFunction = updateDescriptionLabel;
        SendComplexAjaxRequest(urlMethod, jsonData, successFunction, 'DescrMacchina', 'TextBoxDES_MACCHINA');
    }





    /* &lt;== CALLBACK  */
function updateLabelsMacchinaAttributs(msg) {
        var myData = JSON.parse(msg.d);
        $('#' + '&lt;%= this.TextBoxDES_MACCHINA.ClientID  %&gt;').val($.trim(myData["DescrMacchina"]));
    }

    function updateLabelsGuastoAttributs(msg) {
        var myData = JSON.parse(msg.d);
        $('#' + '&lt;%= this.TextBoxDES_GUASTO.ClientID  %&gt;').val($.trim(myData["description"]));
    }

    function updateLabelsCausaGuastoAttributs(msg) {
        var myData = JSON.parse(msg.d);
        $('#' + '&lt;%= this.TextBoxDES_CAUSA_GUASTO.ClientID  %&gt;').val($.trim(myData["description"]));
    }

// BUT I have to generalize it...
function updateDescriptionLabel(msgToParse, dataColumn, TextBoxID) {
        var myData = JSON.parse(msgToParse.d);
        alert(msgToParse);
        alert(dataColumn);
        alert(TextBoxID);

        // this is the explicit call
        $('#' + '&lt;%= this.TextBoxDES_MACCHINA.ClientID  %&gt;').val($.trim(myData["DescrMacchina"]));

        // i want to make the call by using the variables values
        var dCol = dataColumn;
        var txtDes = TextBoxID;

        $('#' + '&lt;%= this.' + txtDes.toString() + '.ClientID %&gt;').val($.trim(myData[dCol]));

        // i get the error: Too many characters in character literal
    }
</code></pre>
