且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ASP.NET用户控件中的JavaScript功能

更新时间:2023-12-06 09:40:16

您需要注册脚本ClientScriptManager$c$c> - 这样可以将它们注册一次,而不管频率的控制已被添加到页:

You need to register your scripts with ClientScriptManager - this way they can be registered once, regardless of how often the control has been added to the page:

// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;

// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname1))
{
  String cstext1 = "alert('Hello World');";
  cs.RegisterStartupScript(cstype, csname1, cstext1, true);
}