Javascript - 如何更改组件的属性?

时间:2014-03-18 22:17:00

标签: javascript asp.net asp.net-ajax

假设我有以下代码:

Sys.Application.add_init(function() {
    $create(
        componentType, 
        {
            "property1":"something", 
            "property2":"something2"
        },
        null, 
        null, 
        $get("element"
    ));
});

如何在代码中更改此创建组件的property1?

1 个答案:

答案 0 :(得分:1)

必须定义ASP.NET Component以提供setter,例如

component.set_property1("new value")

更新相应的“property1”值。 Setter是最初设置属性的方式,因此不具备它们实际上会破坏Component的其他方面。有关其他信息,请参阅Creating Client Components and Controls

然后,这只是“记住”(即存储在变量中)从$create调用返回的组件的问题;客户端/组件ID已知的地方$find可能很有用。由于ASP.NET系统非常复杂,我建议使用$create手动 not ,而只是通过相应的[ASP.NET AJAX] Web控件与组件系统进行交互。 / p>


总之,

$create(t, { "property1":"something" }, ..);

大致相当于

var component = $create(t, {}, ..);
component.set_property1("something");
相关问题