Page.ClientScript.RegisterStartupScript不注入脚本

时间:2015-04-15 02:03:00

标签: javascript c# asp.net

我无法让Page.ClientScript.RegisterStartupScript工作。我已经查看了stackoverflow和其他网站上的所有可能的建议,但似乎没有任何工作。我没有看到"警告"信息。我一直在简化代码,直到我得到一个非常简单的HTML文件和一行C#代码。

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title></title>
  </head>
  <body>
    <form></form>
  </body>
</html>

和后端C#调用:

Page.ClientScript.RegisterStartupScript(this.GetType(), "AlertTab", "Alert('here!')", true);

该脚本根本没有附加到页面上(我没有在浏览器HTML中看到它)。我尝试用<script>..</script>标签包围脚本,但它没有改变任何内容。

正在从Page.ClientScript.RegisterStartupScript

调用

Page_Load

1 个答案:

答案 0 :(得分:0)

试试这个。

Page.ClientScript.RegisterStartupScript(GetType(),
"AlertTab"," <script>alert('here!')</script>", false);