【发布时间】:2011-12-09 20:59:55
【问题描述】:
所以这看起来很有名,但几乎没有什么不同。
JavaScript 函数:
function ShowMessage(Message, Title, isAlarm) {
$("#dtext").html(Message);
$("span.ui-dialog-title").text(Title);
$("#dialog").dialog({
open: function(e) {
var Dia = $(e.target);
if (isAlarm == true) {
Dia.parents(".ui-dialog:first").find(".ui-dialog-titlebar").css("background", "red");
Dia.parents(".ui-dialog:first").find(".ui-dialog-titlebar").css("color", "White");
}
else {
Dia.parents(".ui-dialog:first").find(".ui-dialog-titlebar").css("background", "LightSeaGreen");
Dia.parents(".ui-dialog:first").find(".ui-dialog-titlebar").css("color", "White");
}
},
show: "blind",
hide: "clip",
modal: true,
resizable: false,
buttons: {
"Close": function(e) {
$(this).dialog("close");
return true;
}
}
});
}
如您所见,此方法使用 Jquery-Code 填充。如果这只是 java-script,我们可以使用此代码来调用该函数,但在这种情况下,此方法不能正常工作。
C#调用JS方法:
if (!Pointer.ClientScript.IsStartupScriptRegistered("message"))
Pointer.Page.ClientScript.RegisterStartupScript
(Pointer.Master.GetType(), "message", "ShowMessage('messageBox','" + Message + "',false);", true);
我不知道如何解决这个问题。 I Want just call this Js function from server-side?
编辑 1
感谢您的关注。有些人希望我能更好地描述我的问题。为什么我不能?
因为I don't know what's exactly problem.
我只能说,我用 FireBug 测试这个程序并在 JS 函数的第一行设置断点,但是在运行时,当我调用那个 Js 函数时,断点 Hit 几毫秒,然后页面重新加载完成,什么也没发生。
我是 JS 和 jQuery 的新手。因此,请不要投票尝试使用这些代码的示例程序并帮助我。
再次感谢(特别是 Stefan、PirateKitten、Widor)
编辑 2
我制作了这个Function(JQuery Message Function) 来替换只使用简单 JS 警报的 Old Function。我必须说旧版本的工作(即使我用我写的 JS-Caller-Function 从服务器端调用它)。
在这种情况下,即使 I call new Function(JQ Function) with Js 在页面中像:
<button type="button" onclick="ShowMessage('hi','title',false)">
Display Message
</button>
成功了,但是when call that from server side, Function don't work。
【问题讨论】:
-
会不会是函数被提前调用了?这种改变有效吗?
Pointer.Page.ClientScript.RegisterStartupScript(Pointer.Master.GetType(), "message", "$(function() { ShowMessage('messageBox'," + Message + "',false); }", true); -
您可能应该添加您的确切问题。 JS错误?服务器错误?等
-
你说“工作不好”,你到底是什么意思?您的 javascript 是否无法正确呈现,您是否查看过是否有任何 JS 错误?
-
我用萤火虫试试这个。结果:调用者方法调用了 Js 函数但什么也没发生
-
您尝试过@Manuel 的解决方案吗?这将延迟函数的执行,直到 DOM 完全加载。
标签: c# javascript jquery asp.net