简体   繁体   English

从CodeBehind C#运行多个Javascript

[英]Running multiple Javascripts from CodeBehind C#

I have an ASP.net application that, on one page, I need to run multiple javascripts from C# codebehind. 我有一个ASP.net应用程序,在一页上,我需要从C#代码背后运行多个javascript。 The application sends a transaction to a remote server. 该应用程序将事务发送到远程服务器。 At the start of the routine I want to display a message 'Please Wait'. 在例程开始时,我想显示一条消息“请稍候”。

ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "ShowPleaseWait()", true);

After the transaction is done i want to hide the message. 交易完成后,我想隐藏消息。

ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "HidePleaseWait()", true);

Next I need to print a receipt 接下来,我需要打印收据

ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", "CreditCard()", true);

Only the first script will run. 仅第一个脚本将运行。

You have to combine you JS into one string: 您必须将JS组合成一个字符串:

var js = "<script type=\"text/javascript\">ShowPleaseWait(); HidePleaseWait(); CreditCard();</script>"
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", js, true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM