所以這看起來很有名,但有點不同。從服務器端調用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