tag = only property.get gets called

S

Sam

I've got:
<ParseChildren(True)> _
Public Class UserElement
Inherits WebControl

Public strLabel As new Label

Public Sub New()
strLabel.id = "myID"
End Sub

<PersistenceMode(PersistenceMode.InnerProperty)> _
Public Property objLabel() As Label
Get
Return Me.strLabel
End Get
Set(ByVal value As Label)
me.strLabel = value
End Set

When calling:
<objLabel runat="server">mySecondLabel</objLabel>


I've noticed that only objLabel.set() gets called.
Which means the <objLabel> creates a "new" Label object.
So when the objLabel.set() gets called my old properties like ID (as set
in New()) get overwritten (with nothing, because not set in the tag).
Is there a way that ASP.NET first calles the objLabel.get() and then
"adds" the properties to this existing object?

The other option would be to copy all the properties by hand which is
quite ugly.


Sam.
 
T

Teemu Keiski

Hi,

not sure what you are trying to do besides exposing the Label but as the
Label is instantiated within the control, only get part of the property
makes sense. It returns a reference to the object and that reference can be
used to modify properties of the contained Label. therefore set part doesn't
make sense, because you don't want to reassign the reference, right?

E.g

<PersistenceMode(PersistenceMode.InnerProperty)> _
Public ReadOnly Property objLabel() As Label
Get
Return Me.strLabel
End Get
End Property

This is essentially what you mean by "Is there a way that ASP.NET first
calles the objLabel.get() and then
adds" the properties to this existing object?" as the returned reference is
only needed to modify the contained Label.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top