[英]Calling JS Function From C# Not Working
下午,
以前,我已經可以從C#調用JavaScript函數,並且工作正常。 由於某種原因,這次我斷點代碼時,該功能沒有被調用。
這就是我的C#方法。
public void tester()
{
string returnResult = HttpContext.Current.Session["result"].ToString();
Page.ClientScript.RegisterStartupScript(this.GetType(), "alerify", "alerify('" + returnResult + "');", true);
//ScriptManager.RegisterStartupScript(this, this.GetType(), "alerify", "alerify(" + returnResult + ");", true);
}
您可以看到我嘗試了不同的方法,但是該功能仍然沒有得到實現。
這是我要調用的JavaScript函數。
function alerify(e) {
alert(e);
if (e == "InvalidDates") {
alertify.error("gfgsdggfsdgfsdfd");
}
}
我以為我想念的東西,但我只是不知道。
由於它是一個字符串值,因此需要在JavaScript代碼中使用撇號(或引號)作為字符串文字:
... "alerify('" + returnResult + "');" ...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.