2013-01-16 91 views
1

我有一個文本框(TextBox1)和一個linkbutton(LinkBut​​ton1)的主頁面(default.aspx)。asp.net + jquery ui dialog

當單擊LinkBut​​ton1時,會打開一個jquery ui對話框,其中包含從popup.aspx頁面(使用load方法)加載的內容。

Popup.aspx包含3個鏈接按鈕。

單擊其中一個鏈接按鈕時,我想將linkbutton文本傳回給default.aspx並插入到TextBox1中。

任何解決方案???

來源的Default.aspx:

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
<title></title> 
<script src="http://code.jquery.com/jquery-1.8.3.js" type="text/javascript"></script> 
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js" type="text/javascript"></script> 
<link href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" /> 
<script type="text/javascript"> 
    function OpenDialog() { 
     var $dialog = $('<div></div>').load('./Popup.aspx').dialog({ autoOpen: false, modal: true, title: "Please select value", close: function (ev, ui) { $(this).dialog('close'); } }); 
     $dialog.dialog("open"); 
    } 
</script> 
</head> 
<body> 
    <form id="form1" runat="server"> 
<div> 
    <asp:TextBox ID="TextBox1" runat="server" Enabled="False"></asp:TextBox> 
    <asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="OpenDialog(); return false;">Open selector</asp:LinkButton> 
</div> 
</form> 
</body> 
</html> 

來源POPUP.ASPX:

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <asp:LinkButton ID="LinkButton1" runat="server">Value 1</asp:LinkButton> 
    <asp:LinkButton ID="LinkButton2" runat="server">Value 2</asp:LinkButton> 
    <asp:LinkButton ID="LinkButton3" runat="server">Value 3</asp:LinkButton> 
</form> 
</body> 
</html> 

回答

0

這裏的技巧是讓從窗口頂部的元素,這是通過使用window.top.document作爲:

jQuery("#ElementID", window.top.document) 

,然後因爲你不能從每一頁ID的呈現使用靜態模式ClientIDMode="Static"每個控制,以保持它,你把它寫例如知道:

<asp:TextBox ID="TextBox1" ClientIDMode="Static runat="server" Enabled="False"></asp:TextBox> 

因此,例如從對話框可以發送文字到主窗口爲:

jQuery("#TextBox1", window.top.document).text(jQuery("#LinkButton1").text()); 
0
$(document).on('click', '[id^=LinkButton]', function(){ 
    $('#TextBox1').text($(this).text()); 
});