DynamicScriptReferences1.aspx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <%@ Page Language="C#" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  3. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <script runat="server">
  5. protected void Page_Load(object sender, EventArgs e)
  6. {
  7. // If there is a ScriptManager on the page, use it.
  8. // If not, throw an exception.
  9. ScriptManager Smgr = ScriptManager.GetCurrent(Page);
  10. if (Smgr == null) throw new Exception("ScriptManager not found.");
  11. ScriptReference SRef = new ScriptReference();
  12. //// To set ScriptMode for all scripts on the page...
  13. Smgr.ScriptMode = ScriptMode.Release;
  14. SRef.Path = "~/DynamicScriptReferencesHowTo/Scripts/Scripts.js";
  15. Smgr.Scripts.Add(SRef);
  16. }
  17. </script>
  18. <html xmlns="http://www.w3.org/1999/xhtml">
  19. <head runat="server">
  20. <title>Dynamic Script References</title>
  21. </head>
  22. <body>
  23. <form id="form1" runat="server">
  24. <asp:scriptmanager ID="ScriptManager1" runat="server" />
  25. <div>
  26. </div>
  27. </form>
  28. </body>
  29. </html>