我已将弹出窗口附加到按钮的事件处理程序。
这是我在javascript(asp.net)中的客户端代码:
<script type="text/javascript" language="javascript">
String.Format = function () {
var s = arguments[0];
for (var i = 0; i < arguments.length - 1; i++) {
var reg = new RegExp("\\{" + i + "\\}", "gm");
s = s.replace(reg, arguments[i + 1]);
}
return s;
};
var dialogConfirmed = false;
function SetDialogConfirmedFalse() {
dialogConfirmed = false;
}
function ConfirmDialogInfo(widthX, obj, title, dialogText) {
if (!dialogConfirmed) { //!$('#dialog').is(':data(dialog)')
$('body').append(String.Format("<div id='dialog' title='{0}'>{1}</div>",
title, dialogText));
$('#dialog').dialog({
height: 110,
width: widthX,
modal: true,
resizable: false,
draggable: false,
close: function (event, ui) { $('body').find('#dialog').remove(); },
buttons:
{
'Ok': function () {
$('#dialog').dialog('close');
dialogConfirmed = true;
if (obj) obj.click();
}
}
});
$(".ui-widget").css({ "font-size": +18 + "px" });
}
return dialogConfirmed;
}
function ConfirmDialog(obj, title, dialogText) {
if (!dialogConfirmed) { //!$('#dialog').is(':data(dialog)')
$('body').append(String.Format("<div id='dialog' title='{0}'><p>{1}</p></div>",
title, dialogText));
$('#dialog').dialog({
height: 110,
modal: true,
resizable: false,
draggable: false,
close: function (event, ui) { $('body').find('#dialog').remove(); },
buttons:
{
'Ja': function () {
$('#dialog').dialog('close');
dialogConfirmed = true;
document.getElementById('<%= hdnTestValue.ClientID %>').value = dialogConfirmed;
//document.getElementById("hdnTestValue").value = dialogConfirmed;
//if (obj) obj.click();
},
'Nein': function () {
$('#dialog').dialog('close');
document.getElementById('<%= hdnTestValue.ClientID %>').value = dialogConfirmed;
//document.getElementById("hdnTestValue").value = dialogConfirmed;
}
}
});
$(".ui-widget").css({ "font-size": +18 + "px" });
}
}
</script>
<asp:HiddenField runat="server" ID="hdnTestValue" />
这是我在C#中的服务器端代码:
protected void buttonStopCurrentContract_ButtonPressed(object sender, EventArgs e)
{
var standardMessage = "Do you really want to cancel this contract?";
var script = "ConfirmDialog('this', '" + CommonRes.Attention +
"', '"+ standardMeldung + "');";
ScriptManager.RegisterStartupScript(this, GetType(), Guid.NewGuid().ToString(), script, true);
// hdnTestValue is a hiddenfield
if (hdnTestValue.Value == "true")
{
// do something
}
}
当我运行此代码时,ScriptManager.RegisterStartupScript会一直等到方法结束并弹出对话框。在做出“是”的决定后,决定被保存在隐藏区域中。我必须在按钮上单击两次才能进入if条件。有一个回发问题。我在javascript或asp方面经验不多。任何人都可以给我建议/解决方案吗?
感谢您的期待。