开发者

pass database value as parameter into a Javascript function using jTemplates in ASP.NET?

How to pass database value as parameter into a Javascript function while using jTemplates + jQuery in ASP.NET?

<td>
    <a href="#" title="Click to edit" onclick="AddReturnPopUP($T.record.ITReturnI开发者_C百科D);">
    {formatJSONDate($T.record.AssesmentStartYear)}
</td>

Guys any idea on this?

@Dave :I have seen your post, its great but I just need to pass a particular ID to a javascript function - AddReturnPopUP(param) - which I am unable to do. Posting the code:

<script id="jTemplate" type="text/html">
                <table border="1" cellpadding="3" cellspacing="2" class="mGrid">
                    <thead>
                        <tr>
                            <th>
                                Assesment Start Year
                            </th>
                            <th>
                                Assesment End Year
                            </th>
                            <th>
                                Returned Income
                            </th>
                            <th>
                                Tax Paid
                            </th>
                            <th>
                                Last Update
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        {#foreach $T.d as record}
                        <tr class="{#cycle values=['','alt']}">
                            <td>
                                <a href="#" title="Click to edit" onclick="AddReturnPopUP($T.record.ITReturnID);">
                                                {formatJSONDate($T.record.AssesmentStartYear)}
                            </td>
                            <td>
                                {formatJSONDate($T.record.AssesmentEndYear)}
                            </td>
                            <td>
                                {$T.record.ReturnedIncome}
                            </td>
                            <td>
                                {$T.record.TaxPaid}
                            </td>
                            <td>
                                {formatJSONDate($T.record.LastUpdate)}
                            </td>
                        </tr>
                        {#/for}
                    </tbody>
                </table>
                </script>

Setting up the jTemplate:

function PopulateReturns()
    {
        var param = {clientId: qs};
        var data = JSON.stringify(param);
        $.ajax({
                type: "POST",
                url: "EditClient.aspx/GetReturns",
                data: data,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function success(data) {
                                     $('#placeHolder').setTemplate($("#jTemplate").html());
                                     $('#placeHolder').processTemplate(data);
                },
                error: function (xhr, status, e) {
                    //var err = JSON.parse(xhr.responseText); $("#placeHolder").html("Error:" + err.Message);  
                }
            });
    }

What I need is to pass the value of $T.record.ITReturnID as a parameter into the Javascript function - AddNewReturn(Id) which presently throws an exception: $T is not defined Please let me know if you need more details.


If you haven't seen it seen, I've got a full example of using ASP.NET, jQuery, and jTemplates to do something like that: http://encosia.com/2008/06/26/use-jquery-and-aspnet-ajax-to-build-a-client-side-repeater/

If that doesn't help, update your question with more details. We need to see more of your template code, the JavaScript you're using to render the template, and more detail on the data structure you're trying to render.

Worth noting, if you're starting from scratch, I'd recommend using jQuery Templates instead of jTemplates. jTemplates was great, but jQuery Templates is much more actively supported/developed.

edit:

Change your onclick attribute like this:

<a href="#" title="Click to edit" onclick="AddReturnPopUP({$T.record.ITReturnID});">

That should correctly inject the ITReturnID value.


Just pass this : onclick="AddReturnPopUP('{$T.record.ITReturnID}');" The js function will work correctly!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜