2012-10-15 87 views
1

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

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> 

我已经试过这一点,但它给错误 “服务器标记不能包含<%...%>”

<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> 

请帮助。提前致谢。

+0

任何人有任何建议吗? – Milacay

回答

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 - 确保在客户端正确的URL(除非你是肯定的网址是什么)

你也应该知道,.live()被弃用的jQuery 1.7,你应该使用.on()

+0

感谢您的回复。我尝试了您的建议,但不断收到错误“Them Name'ProposalID'不在当前上下文中”。也许,这个标签是在DetailsView里面的,我们无法检测到Text值?请指教。 – Milacay

+0

@Milacay我看你已经更新了你的.ASPX代码 - 我已经将span元素的选择器更改为更一般的基于此,请现在测试(我在这里有点猜测,因为页面上可能有其他的东西这可能会使事情变得复杂一些)。 – tpeczek

+0

这工作完美!非常感谢!快速提问。如果我想隐藏ID在。你可以使用相同的方法来捕获ProposalID吗? – Milacay

相关问题