ScriptControlDescriptor.AddProperty & Read-Only Properties

I am creating ASP.NET Server Control with the appropriate client-side API.

In my GetScriptDescriptors () method, I bind a property called "rows" ...

descriptor.AddProperty("rows", this.IntRows); 

In my client-side API, I want my "rows" property to be read-only ...

 MyControl = function(element) { MyControl.initializeBase(this, [element]); this._rows; } MyControl.prototype = { initialize: function() { MyControl.callBaseMethod(this, 'initialize'); }, get_rows: function() { return this._rows; }, dispose: function() { MyControl.callBaseMethod(this, 'dispose'); } } 

However, this causes the following error ...

Error: Sys.InvalidOperationException: "rows" is not writeable.

It seems that the following typesetter is required in order for the $ create operator to set the "strings" to its initial value:

 set_rows: function(value) { this._rows = value; }, 

How can I make the "rows" property read-only in the client-side API if the setter needs to assign a value from the AddProperty call?

+4
source share
1 answer

The simplest method would be to force set_rows to ignore any input. Effectively, this should completely throw an Exception and still provide read-only functions for this property.

 set_rows: function(value) { value = null; }, 
0
source

Source: https://habr.com/ru/post/1304378/


All Articles