0

alert('mytext');我在使用through 时遇到问题ScriptManager.RegisterStartupScript()

问题是,当我在循环中使用它时,例如,通过编写:

for(int i = 0; i < 3; i++)
{
    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alert", "alert('Hello World');", true);
}

警报显示一次,而不是三次。

准确地说,该函数有 5 个参数,它们是:

  • Control control: 页面控制
  • Type typeOfControl: 类型Control
  • string key: 用于标识 JS 脚本的键
  • string script: JS 脚本本身
  • boolean addScriptTags<script></script>:是否放入脚本

问题的本质是我无法指定另一个key. 我尝试使用毫秒来识别每个脚本,但似乎脚本更快,因此具有相同的毫秒数(而且我不能更精确地处理时间......)。

问题:如何对key参数使用可能的唯一标识符?还是有替代方案?

4

0 回答 0