所以这看起来很有名,但有点不同。从服务器端调用JavaScript函数?
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的代码。如果这只是java脚本,我们可以使用此代码来调用该函数,但在这种情况下,此方法效果不佳。
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
感谢您的关注。有些人想从我这里更好地描述我的问题。为什么我不能? Cuz I don't know what's exactly problem
。
我可以说,我测试这个程序使用Firebug和对JS的功能,但在运行时,第一行设置断点,当我将其称为是突破点Hit
几毫秒和JS函数,那么页面重载云完成并没有发生。
我是JS和jQuery的新手。所以反而打倒投票plz 尝试这些代码的示例程序,并帮助我。
再次感谢(特别斯特凡,PirateKitten,Widor)
编辑2
我做了这个Function(JQuery Message Function)
更换Old Function
只使用简单的JS警报。我必须说旧版本的工作(即使我从服务器端调用JS编写的调用函数)。
,即使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错误?服务器错误?等 – Stefan
你说过“工作不好”,你的意思是什么?你的JavaScript没有正确渲染,你看过吗?看看你是否有任何JS错误? – Kasaku