我正在尝试根据超出特定范围的值从我的C#ASP.NET代码打开jQuery UI对话框,而不是基于按钮单击或其他客户端事件。这是应该创建对话框的Javascript函数(位于.aspx页面的顶部):
<script type="text/javascript">
//Total out of range dialog
function ShowRangeDialog() {
$('#rangeDialog').dialog({
modal: true,
width: 'auto',
resizable: false,
draggable: false,
close: function (event, ui) {
$('body').find('#rangeDialog').remove();
},
buttons:
{
'OK': function () {
$(this).dialog('close');
}
}
});
}
</script>
这是对话框div本身(在.aspx页面的底部):
<div id="rangeDialog" style="display: none;" title="Total out of range">
<p>
Your line items total is out of the range allowed by the approval level you chose.
Please check the approval range and adjust the line items or quantities.
</p>
</div>
以下是试图显示对话框的C#代码部分:
if (currTotal < lowerLim || currTotal > upperLim)
{
//Show jQuery dialog telling user that their line items total is out of range
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "dlgOutOfRange",
"ShowRangeDialog();", true);
}
如果我在调试器中单步调试if
块中的代码,但是没有显示该对话框。我错过了什么?
答案 0 :(得分:1)
我根据我在How do I open a jQuery UI Dialog from my c# code behind?找到的问题/答案稍微修改了我的功能,现在它可以正常工作了。这是修改后的功能:
<script type="text/javascript">
//Total out of range dialog
function ShowRangeDialog() {
$(function() {
$('#rangeDialog').dialog({
modal: true,
width: 'auto',
resizable: false,
draggable: false,
close: function (event, ui) { $('body').find('#rangeDialog').remove(); },
buttons: { 'OK': function () { $(this).dialog('close'); }
}
})
}).dialog("open");
}
</script>
答案 1 :(得分:0)
试试这个
if (currTotal < lowerLim || currTotal > upperLim)
{
//Show jQuery dialog telling user that their line items total is out of range
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "dlgOutOfRange",
"ShowRangeDialog();", true);
}
你应该只是调用函数名。
此外,您可能想尝试使用startupscript而不是registerclientscriptblock。您必须确保在定义函数之后添加脚本,而不是之前。
if (currTotal < lowerLim || currTotal > upperLim)
{
//Show jQuery dialog telling user that their line items total is out of range
Page.ClientScript.RegisterStartupScript(this.GetType(), "dlgOutOfRange",
"ShowRangeDialog();", true);
}