tag = only property.get gets called

Discussion in 'ASP .Net Building Controls' started by Sam, Jul 26, 2005.

  1. Sam

    Sam Guest

    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.
    Sam, Jul 26, 2005
    #1
    1. Advertising

  2. Sam

    Teemu Keiski Guest

    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.
    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke



    "Sam" <> wrote in message
    news:42e6121f$0$20279$...
    > 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.
    Teemu Keiski, Jul 28, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shruds
    Replies:
    1
    Views:
    747
    John C. Bollinger
    Jan 27, 2006
  2. Stefan Mueller
    Replies:
    5
    Views:
    505
    Steven Saunderson
    Jul 10, 2006
  3. John Joyce

    gets gets

    John Joyce, Mar 26, 2007, in forum: Ruby
    Replies:
    2
    Views:
    332
    John Joyce
    Mar 26, 2007
  4. John Joyce

    Return of gets gets

    John Joyce, Apr 23, 2007, in forum: Ruby
    Replies:
    0
    Views:
    180
    John Joyce
    Apr 23, 2007
  5. libsfan01
    Replies:
    5
    Views:
    229
    Jeff North
    Dec 20, 2006
Loading...

Share This Page