4

I'm creating an ASP.NET Server Control with an associated client-side API.

In my GetScriptDescriptors() method I'm associating 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 a writable property.

The following setter seems to be required in order for the $create statement to assign "rows" it's 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 is required to assign the value from the AddProperty call?

Brett Postin
  • 11,215
  • 10
  • 60
  • 95

1 Answers1

0

Simplest method would be to have the set_rows ignore any input. Effectively this should stop the Exception from occurring altogether and still provide Read Only functionality to the property.

set_rows: function(value)
{
    value = null;
},
BinaryMisfit
  • 29,219
  • 2
  • 37
  • 44
  • Thanks for the reply. I haven't had chance to test it yet. However I'm not sure I follow your sample. Wouldn't that simply clear the "rows" value if the setter was called? – Brett Postin Jan 21 '11 at 09:10
  • @Poz Your correct it would. I set the wrong option to null. The other alternative would be to throw a not implemented exception, however that will need to be handled by the coder. Rather just silently ignore the set. – BinaryMisfit Jan 21 '11 at 09:22