现在我有一个巨大的解决方案,我们通过 RegisterStartupScript 对所有消息和错误使用 javascript 警报。我们愿意修改所有这些以制作类似于 modalPopupExtender 或扩展器本身的东西,而不需要太多付出了很多努力...我的意思是,要在单个页面上显示模态弹出窗口,我需要在 aspx 文件上创建它,设置属性等...所以我只是在寻求想法,想知道你们如何处理这..
问问题
175 次
2 回答
1
您不能将模态弹出/模态弹出扩展器放入用户控件并将用户控件嵌入到每个页面中吗?
于 2009-07-09T15:08:09.377 回答
1
我可能会使用 jQuery 对话框并将标记和初始化代码放在 MasterPage 中,autoOpen
默认设置为 false 并隐藏。我会根据需要将与对话框交互的代码注入每个页面。
<div id="modalDialog" title="Error">
<p id='modalDialogMsg'>An error has occurred.</p>
</div>
<script type="text/javascript">
$(function() {
$('#modalDialog').dialog({
autoOpen: false;
modal: true,
buttons: {
"OK" : function() {
$(this).dialog('close');
}
}
});
});
// You could "objectify" this, but I'll show as a global function
function showError( title, msg )
{
if (!title) {
title = 'Error';
}
if (!msg) {
msg = 'An error occurred.';
}
$('#modalDialogMessage').html(msg);
$('#modalDialog').attr('title',title)
.dialog('open');
}
</script>
然后,在您的页面中,您将注入调用 showError 的代码。请注意,这需要在上面的脚本之后,以确保已定义函数。吐出来的会是这样的:
<script type="text/javascript">
$(function() {
showError('Database connection error', 'There was an error connecting to the database.' )'
});
</script>
于 2009-07-09T15:22:01.780 回答