Add JavaScript reference from code behind (C#)

前端 未结 3 997
耶瑟儿~
耶瑟儿~ 2021-02-08 12:24

Is it possible to add javascript reference dynamically from code behind aspx.cs?

Like this:

private void AddScriptReference(string path)
{
   //Add refer         


        
3条回答
  •  失恋的感觉
    2021-02-08 12:59

    Bit late but thought I'd post an answer to this in case anybody else needs it. This solution negates the need for a ScriptManager.

    Basically, it's just a case of creating a control and then adding to the head. Here's the code.

    LiteralControl javascriptRef = new LiteralControl("");
    
    Page.Header.Controls.Add(javascriptRef);
    

提交回复
热议问题