将RecordID传递给Jquery UI对话框

时间:2012-10-15 16:33:02

标签: jquery asp.net

我的DetailsView上方有一个按钮。当我单击它时,它将弹出一个“插入注释”对话框(iframe中的另一个页面),此对话框正在使用Jquery。我无法弄清楚如何在对话框弹出窗口中将recordID传递给此插入页面。

Jquery代码:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> 
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.ui/1.8.6/jquery-ui.min.js"></script> 
<link type="text/css" rel="Stylesheet" href="http://ajax.microsoft.com/ajax/jquery.ui/1.8.6/themes/smoothness/jquery-ui.css"> 
<script type="text/javascript">
    $(document).ready(function () {
        $('#AddNewProposal').live('click', function (e) {
            e.preventDefault();
            var page = $(this).attr("href")
            //var page = "ProposalCreateNew.aspx"
            var pagetitle = $(this).attr("title")
            alert(page);
            var $dialog = $('<div></div>')
            .html('<iframe style="border: 0px; " src="' + page + '" width="100%" height="100%"  frameBorder="0"  align="middle"> ></iframe>')
            .dialog({
                autoOpen: false,
                modal: true,
                height: 650,
                width: 900,
                title: pagetitle
            });
            $dialog.dialog('open');
        });
    });
</script> 

我试过这个,但是它给出了错误“服务器标签不能包含&lt;%...%&gt;”

<table width="80%" align="center" >
    <tr>
        <td width="20%"></td>
        <td width="80%" class="PageTitle"></td>
        <td width="20%">
            <asp:Button runat="server" CommandName="AddNewProposal" ID="AddNewProposal" Text="Create New" href="ProposalCreateNote.aspx" title="Create Note" class="button3"/>              
        </td>
    </tr>
</table
--- Below is my DetailsView which has a label to display the ProposalID, so I want to grab this ID and pass it to the dialog box (URL + ID) when I click the AddNewProposal button.
<asp:TemplateField HeaderText="ProposedID" SortExpression="Name" > 
     <ItemTemplate >
          <asp:Label ID="ProposalID" runat="Server" 
          style="text-align:left;" Text='<%# Eval("ProposedID")%>' />
     </ItemTemplate>
</asp:TemplateField>

请帮忙。提前谢谢。

1 个答案:

答案 0 :(得分:0)

Label服务器控件正在客户端生成span元素,因此您应该能够获得如下文本:

<script type="text/javascript">
$(document).ready(function () { 
    $('#<%= AddNewProposal.ClientID %>').live('click', function(e) {
        e.preventDefault();
        var page = '<%= ResolveClientUrl("~/ProposalCreateNew.aspx")%>' + '?ProposalID=' + encodeURIComponent($('span[id$="ProposalID"]').text());
        var pagetitle = $(this).attr("title");
        alert(page);
        var $dialog = $('<div></div>')
        .html('<iframe style="border: 0px; " src="' + page + '" width="100%" height="100%"  frameBorder="0"  align="middle"> ></iframe>')
        .dialog({
            autoOpen: false,
            modal: true,
            height: 650,
            width: 900,
            title: pagetitle
        });
        $dialog.dialog('open');
    });
});
</script>

请注意使用:

  • ClientID - 为确保您定位正确的元素,ASP.NET WebForms ID在客户端可能不同(除非您在ASP.NET 4.0中使用ClientIDMode.Static
  • ResolveClientUrl - 确保客户端的正确网址(除非您确定该网址是什么)

您还应该知道,从jQuery 1.7开始,.live()已弃用,您应该使用.on()