代码之家  ›  专栏  ›  技术社区  ›  Nelson Rothermel

多个ScriptControl实例共享变量

  •  0
  • Nelson Rothermel  · 技术社区  · 15 年前

    ScriptControl 使用图像作为嵌入资源 GetWebResourceUrl 生成 WebResource.axd GetScriptDescriptors() 将URL发送到JavaScript对象。

    这个 可以在一个 Repeater 控制类型 ->控制实例)?

    1 回复  |  直到 15 年前
        1
  •  0
  •   Nelson Rothermel    15 年前

    这似乎很有效:

            string imagesScript = String.Format(
                "MyNamespace.MyClass.prototype.imgDisabled = '{0}';" +
                "MyNamespace.MyClass.prototype.imgEnabled = '{1}';",
                Page.ClientScript.GetWebResourceUrl(typeof(MyClass), "MyNamespace.disabled.png"),
                Page.ClientScript.GetWebResourceUrl(typeof(MyClass), "MyNamespace.enabled.png")
            );
    
            Page.ClientScript.RegisterStartupScript(typeof(MyClass), "Images", imagesScript, true);
    

    在我的物品里我只是 this.imgDisabled this.imgEnabled 获取网址。

    编辑: AssemblyInfo.cs 将JavaScript引用设置为 WebResource(..., PerformSubstitution = true) 那么.js文件可以 <%= WebResource("MyNamespace.enabled.png") %> 任何你想去的地方。这可以是您实际使用它或添加到对象原型的位置。

    推荐文章