我有一个 asp.net listview
控件,其itemtemplate
中有一个asp:button
。我想在单击Colorbox
并满足某些条件时打开它(这就是为什么我在调用 onclientclick 时遇到问题),并且颜色框将显示一个 iframe。我尝试了许多不同的方法,并在谷歌上搜索了很多,但没有一个答案对我有用,因为它们都在建议onclientclick
事件而不是在点击上。
我正在使用如下所示的代码在 Colorbox 模式对话框中打开 href 链接:
<script>
$(document).ready(function () {
$(".ajax").colorbox();
$(".iframe").colorbox({ iframe: true,
width: "50%", height: "500px" });
});
</script>
但是我无法让它在 asp.net 列表视图的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>