[英]How to open Colorbox jquery plugin modal window from asp.net code behind?
我有一個asp.net listview
控件,在其itemtemplate
有一個asp:button
。 我想在點擊時打開Colorbox
並滿足某些條件(這就是我在調用onclientclick時遇到問題)並且Colorbox將顯示iframe。 我嘗試了許多不同的方式並且用Google搜索了很多,但是沒有一個答案對我有用,因為他們所有人都建議onclientclick
事件而不是onclick。
我正在使用如下代碼在Colorbox模式對話框中打開href鏈接:
<script>
$(document).ready(function () {
$(".ajax").colorbox();
$(".iframe").colorbox({ iframe: true,
width: "50%", height: "500px" });
});
</script>
但我無法在asp.net listview的itemcommand
事件中使用代碼隱藏工作。
你能建議一個解決方案嗎?
您可以在頁面上創建一個隱藏字段並將其設置在代碼隱藏中,然后在$(document).ready()
上進行檢查。
例如:
頁
<script>
$(document).ready(function () {
$(".ajax").colorbox();
$(".iframe").colorbox({ iframe: true, width: "50%", height: "500px" });
if ($('.showColorbox').val()) {
// show the colorbox
}
});
</script>
代碼隱藏:
// in click event code
showColorbox.Value = true;
這是我最終的結果:
<asp:Button ID="btnViewDetails" runat="server" Text="Details" OnClientClick="
OpenCBox();" />
<script type="text/javascript">
function OpenCBox() {
$.colorbox({ href: '<%# Eval("EditLink") %>', iframe: true, width: "50%", height: "500px",
transition: "elastic", onClosed: function () { parent.location.reload(true); } });
return true;
}
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.