【问题标题】:javascript in ajax asp net controlajax asp net 控件中的javascript
【发布时间】:2012-11-14 18:50:16
【问题描述】:

这是创建 javascript 对象的函数

      public IEnumerable<ScriptDescriptor>
          GetScriptDescriptors()
    {
        ScriptControlDescriptor descriptor = new ScriptControlDescriptor("HierarchyPathControl.PathExplorer", this.ClientID);
        descriptor.AddProperty("some_property", "some_value");

        yield return descriptor;
    }

这是 .js 文件的一部分

    Type.registerNamespace("HierarchyPathControl");

        HierarchyPathControl.PathExplorer = function (element) {
        HierarchyPathControl.PathExplorer.initializeBase(this, [element]);
        alert("invoked");

    }


  HierarchyPathControl.PathExplorer.prototype = {
       initialize: function () {

        HierarchyPathControl.PathExplorer.callBaseMethod(this, 'initialize');
        alert("not invoked");   

},
..............................

为什么只有当我删除此行时才会调用第二个警报:

    descriptor.AddProperty("some_property", "some_value");

谢谢。

【问题讨论】:

  • 您是否看到任何 javascript 错误?

标签: javascript asp.net asp.net-ajax custom-server-controls


【解决方案1】:

如果在页面初始化过程中出现 js 错误,请检查错误控制台。问题似乎是您没有在客户端类中定义 some_property 属性。 确保在 HierarchyPathControl.PathExplorer 客户端类中具有以下 get/set 方法定义:

get_some_property = function() {
    return this._some_property;
},
set_some_property = function(value) {

    if (this._some_property != value) {
        this._some_property = value;
        this.raisePropertyChanged('some_property');
    }
}

这里基本上 some_property 应该是您要创建的属性的名称。

【讨论】:

  • 很好!我读了很多文章,但没有人说它必须是 getter 和 setter。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-14
  • 2017-01-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-13
相关资源
最近更新 更多