Copying A Control Not As A Reference

Discussion in 'ASP .Net Web Controls' started by Nathan Sokalski, Jun 12, 2006.

  1. I have a Control that I want to copy as a copy of the Control, not a copy of
    the reference to the original. My reason for doing this is because some of
    the methods I would calling would prevent proper rendering afterwards. I
    access the Control as a parameter of a function, as follows:

    Private Function MyFunction(ByVal ctrl As Control) As String
    'code that will make a copy of ctrl
    'my function code
    End Function

    (NOTE: I am using VB.NET and .NET Framework 1.1) Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
    Nathan Sokalski, Jun 12, 2006
    #1
    1. Advertising

  2. Nathan Sokalski

    tomb Guest

    Nathan Sokalski wrote:

    >I have a Control that I want to copy as a copy of the Control, not a copy of
    >the reference to the original. My reason for doing this is because some of
    >the methods I would calling would prevent proper rendering afterwards. I
    >access the Control as a parameter of a function, as follows:
    >
    >Private Function MyFunction(ByVal ctrl As Control) As String
    > 'code that will make a copy of ctrl
    > 'my function code
    >End Function
    >
    >(NOTE: I am using VB.NET and .NET Framework 1.1) Thanks.
    >
    >

    You have to pass the ctrl ByRef in order to be working with the one you
    want to copy.

    T
    tomb, Jun 12, 2006
    #2
    1. Advertising

  3. That does not help. Let me try explaining my problem differently with an
    example:

    Private Function MyFunction(ByVal ctrl As Control) As String
    dim copyofctrl as Control

    'copyofctrl=ctrl this will be replaced with code that will assign a
    copy of ctrl to copyofctrl that points to a new instance of whatever type
    ctrl was
    'my function code
    End Function

    In the part of my code labeled "my function code" I want to be able to do
    ANYTHING I WANT to the local variable copyofctrl without having any effect
    on ctrl. Hopefully this clears up what I am trying to do.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "tomb" <> wrote in message
    news:RV5jg.71053$...
    > Nathan Sokalski wrote:
    >
    >>I have a Control that I want to copy as a copy of the Control, not a copy
    >>of the reference to the original. My reason for doing this is because some
    >>of the methods I would calling would prevent proper rendering afterwards.
    >>I access the Control as a parameter of a function, as follows:
    >>
    >>Private Function MyFunction(ByVal ctrl As Control) As String
    >> 'code that will make a copy of ctrl
    >> 'my function code
    >>End Function
    >>
    >>(NOTE: I am using VB.NET and .NET Framework 1.1) Thanks.
    >>

    > You have to pass the ctrl ByRef in order to be working with the one you
    > want to copy.
    >
    > T
    Nathan Sokalski, Jun 12, 2006
    #3
  4. Nathan,

    If a class is serializable you can almost forever copy something to
    serialize the object first and than deserialize it again.

    http://www.vb-tips.com/default.aspx?ID=7ffd296f-9e81-47e6-88dc-61641f5c8d9d

    I hope this helps,

    Cor

    "Nathan Sokalski" <> schreef in bericht
    news:%...
    >I have a Control that I want to copy as a copy of the Control, not a copy
    >of the reference to the original. My reason for doing this is because some
    >of the methods I would calling would prevent proper rendering afterwards. I
    >access the Control as a parameter of a function, as follows:
    >
    > Private Function MyFunction(ByVal ctrl As Control) As String
    > 'code that will make a copy of ctrl
    > 'my function code
    > End Function
    >
    > (NOTE: I am using VB.NET and .NET Framework 1.1) Thanks.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    Cor Ligthert [MVP], Jun 12, 2006
    #4
  5. "tomb" <> schrieb:
    >>I have a Control that I want to copy as a copy of the Control, not a copy
    >>of the reference to the original. My reason for doing this is because some
    >>of the methods I would calling would prevent proper rendering afterwards.
    >>I access the Control as a parameter of a function, as follows:
    >>
    >>Private Function MyFunction(ByVal ctrl As Control) As String
    >> 'code that will make a copy of ctrl
    >> 'my function code
    >>End Function
    >>
    >>(NOTE: I am using VB.NET and .NET Framework 1.1) Thanks.

    >
    > You have to pass the ctrl ByRef in order to be working with the one you
    > want to copy.


    No, you should pass it 'ByVal' because 'Control' is already a reference
    type.

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://classicvb.org/petition/>
    Herfried K. Wagner [MVP], Jun 12, 2006
    #5
    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. Nathan Sokalski

    Copying A Control Not As A Reference

    Nathan Sokalski, Jun 12, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    4,687
    Herfried K. Wagner [MVP]
    Jun 12, 2006
  2. aurora
    Replies:
    6
    Views:
    380
    =?ISO-8859-1?Q?Michael_Str=F6der?=
    Oct 18, 2004
  3. techieV
    Replies:
    2
    Views:
    297
    Marcel Müller
    Feb 21, 2011
  4. Nathan Sokalski

    Copying A Control Not As A Reference

    Nathan Sokalski, Jun 12, 2006, in forum: ASP .Net Building Controls
    Replies:
    4
    Views:
    114
    Herfried K. Wagner [MVP]
    Jun 12, 2006
  5. Replies:
    14
    Views:
    229
    Tomi Häsä
    Jan 10, 2005
Loading...

Share This Page