从C#code调用JavaScript背后 [英] Invoke JavaScript from C# code behind
本文介绍了从C#code调用JavaScript背后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想学习asp.net。假设我有这个code:
I am trying to learn asp.net. Assuming that I have this code:
if (command.ExecuteNonQuery() == 0)
{
// JavaScript like alert("true");
}
else
{
// JavaScript like alert("false");
}
如何,我可以从C#code后面调用JavaScript?如何做到这一点通过把的JavaScript在脚本
这是默认的MS Visual Studio中创建的目录?
How to I can invoke JavaScript from C# code behind? How to do that by putting that JavaScript in Scripts
directory which is created by default in MS Visual Studio?
推荐答案
下面是我的方法将时间使用时间从code发送弹出消息后面。我尽量避免这样做 - 但有时我需要
Here is method I will use from time to time to send a pop message from the code behind. I try to avoid having to do this - but sometimes I need to.
private void LoadClientScriptMessage(string message)
{
StringBuilder script = new StringBuilder();
script.Append(@"<script language='javascript'>");
script.Append(@"alert('" + message + "');");
script.Append(@"</script>");
Page.ClientScript.RegisterStartupScript(this.GetType(), "messageScript", script.ToString());
}
这篇关于从C#code调用JavaScript背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文