Question

Supposed I have the following code:

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

How could I change property1 of this created component in my code?

Was it helpful?

Solution

The ASP.NET Component must be defined to provide setters, such that

component.set_property1("new value")

updates the corresponding "property1" value. Setters are how the properties are initially set, so not having them will actually break other aspects of the Component. See Creating Client Components and Controls for additional information.

Then it's just a matter of "remembering" (i.e. store in a variable) the Component returned from the $create invocation; where the Client/Component ID is known $find can be useful. Since the ASP.NET system is quite complex, I would recommend not manually using $create, but rather only interact with the component system through the corresponding [ASP.NET AJAX] Web Controls.


In summary,

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

is roughly equivalent to

var component = $create(t, {}, ..);
component.set_property1("something");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top