---
title: "jQuery - jTemplates - Ladda in UserControl"
type: "forum-thread"
url: "https://www.webforum.nu/amne/dotnet/176585-jquery-jtemplates-ladda-in-usercontrol"
topic: ".NET"
topic_url: "https://www.webforum.nu/amne/dotnet"
author: "PBF"
published: "2009-01-29T11:31:13.000Z"
updated: "2009-01-29T11:31:13.000Z"
replies: 0
views: 352
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/dotnet/176585-jquery-jtemplates-ladda-in-usercontrol"
---

# jQuery - jTemplates - Ladda in UserControl

## #1 — PBF, 2009-01-29T11:31Z

Tjenare!

Använder följande kod för att försöka köra med templates istället då jag hört att det är mycket snabbare:

```
    J(document).ready(function() {
        J("#show-sent-messages").click(function() {
            LoadSentMessages();
        });
        
    });
    
    function LoadSentMessages() {
        J.ajax({
            type: "GET",
            url: "GenericHandlers/PersonalMessage.ashx?do=getSent",

            cache:false,
            contentType: "application/json; charset=utf-8",
            dataType: "json", 

            success: function(sentMessages) {
                ApplyTemplate(sentMessages);
            } 
        });
    }
    
    function ApplyTemplate(msg) {
     J('#template').setTemplateURL('table2.tpl');
     J('#template').processTemplate(msg);
    }
```

table2.tpl:

```
<table>
  <thead>
    <tr>
      <th>Date</th>
      <th>Title</th>
      <th>No No No</th>
    </tr>
  </thead>
  <tbody>
    {#foreach $T as post}
    
            <tr class="AlternatingItem">
            <td style="width: 120px;">
                <strong>
                    <asp:HyperLink ID="hlProfile" runat="server" NavigateUrl='~/User/PersonalMessages.aspx?ID={$T.post.Reciever.UserID}"'>{$T.post.Reciever.Username}</asp:HyperLink></strong>
            </td>
            <td style="width: 250px;">
                <a id="ShowMessageSent" runat="server" style="cursor: pointer;">
                    {$T.post.Subject}</a>
            </td>
            <td style="width: 120px;">
                {$T.post.Posted}
            </td>
            <td>
                <asp:Label ID="lblReadStatus" runat="server"></asp:Label>
            </td>
            <td style="text-align: right;">
                <input id="hiddenID" type="hidden" />
                <asp:CheckBox ID="cbAction" Text='{$T.post.ID}' Style="font-size: 0px;" EnableViewState="true"
                    runat="server" />
            </td>
        </tr>
        <tr>
            <td colspan="5">
                <div id='MessageSent-{$T.post.ID}' style="display: none; padding: 15px;">
                    {$T.post.Message}<br />
                    <br />
                </div>
            </td>
        </tr>

    {#/for}
  </tbody>
</table>
```

Allt fungerar här och den laddar in korrekt data.

Problemet är nu att jag t.ex. inte kan använda mig av HyperLinks etc, och lite andra nackdelar med \*.tpl-filer.

Vet någon om det går att köra såhär med User Controls (ashx-filer) istället?

Permalänk: https://www.webforum.nu/p/176585

---

Tråden på webben: https://www.webforum.nu/amne/dotnet/176585-jquery-jtemplates-ladda-in-usercontrol
