How to duplicate a control?

Discussion in 'ASP .Net Building Controls' started by Neo, Aug 14, 2004.

  1. Neo

    Neo Guest

    Hi,

    I want to place two buttons on the page. These two button are identical.Is
    there a way to duplicate a button? or I have to assign all properties of one
    button to another.

    Thanks in advance.

    Neo
    Neo, Aug 14, 2004
    #1
    1. Advertising

  2. Hi Neo,

    If you're looking for something like:

    Button btn2 = btn1.Clone ();

    Then no, there is no such easy thing for cloning controls, sorry!

    --
    Victor Garcia Aprea
    Microsoft MVP | ASP.NET
    Looking for insights on ASP.NET? Read my blog:
    http://obies.com/vga/blog.aspx
    My profile: http://aspnet2.com/mvp.ashx?vga

    "Neo" <> wrote in message
    news:u$...
    > Hi,
    >
    > I want to place two buttons on the page. These two button are

    identical.Is
    > there a way to duplicate a button? or I have to assign all properties of

    one
    > button to another.
    >
    > Thanks in advance.
    >
    > Neo
    >
    >
    Victor Garcia Aprea [MVP], Aug 15, 2004
    #2
    1. Advertising

  3. Neo

    Neo Guest

    Hi Victor,

    Actually, what I want to do is to add two identical buttons on the page.
    It seems that a button can not be added twice on the page.(I tried to add a
    button to two placeholders and only last placeholder had the button)

    So is there a way to add identical buttons on the page or an easy way to
    copy one button's property to another?

    Thanks

    Neo

    "Victor Garcia Aprea [MVP]" <> wrote in message
    news:...
    > Hi Neo,
    >
    > If you're looking for something like:
    >
    > Button btn2 = btn1.Clone ();
    >
    > Then no, there is no such easy thing for cloning controls, sorry!
    >
    > --
    > Victor Garcia Aprea
    > Microsoft MVP | ASP.NET
    > Looking for insights on ASP.NET? Read my blog:
    > http://obies.com/vga/blog.aspx
    > My profile: http://aspnet2.com/mvp.ashx?vga
    >
    > "Neo" <> wrote in message
    > news:u$...
    > > Hi,
    > >
    > > I want to place two buttons on the page. These two button are

    > identical.Is
    > > there a way to duplicate a button? or I have to assign all properties of

    > one
    > > button to another.
    > >
    > > Thanks in advance.
    > >
    > > Neo
    > >
    > >

    >
    >
    Neo, Aug 17, 2004
    #3
  4. You can't add two buttons to the page with the same ID. I'm assuming these
    are both server-side button controls. What you could do is create a new
    button with a different ID and the same value like

    <asp:Button id="Button1" runat="server" Text="Button"
    OnClick="Button_OnClick"></asp:Button>
    ....
    <asp:Button id="Button2" runat="server" Text="Button"
    OnClick="Button_OnClick"></asp:Button>

    This way the same method (Button_OnClick) will be called when either one is
    clicked but they both look the same. My understanding is that
    Button1_OnClick and Button2_OnClick events are also available, so you could
    leave the OnClick property out and call Button_OnClick from each event
    handler.

    "Neo" wrote:

    > Hi Victor,
    >
    > Actually, what I want to do is to add two identical buttons on the page.
    > It seems that a button can not be added twice on the page.(I tried to add a
    > button to two placeholders and only last placeholder had the button)
    >
    > So is there a way to add identical buttons on the page or an easy way to
    > copy one button's property to another?
    >
    > Thanks
    >
    > Neo
    >
    > "Victor Garcia Aprea [MVP]" <> wrote in message
    > news:...
    > > Hi Neo,
    > >
    > > If you're looking for something like:
    > >
    > > Button btn2 = btn1.Clone ();
    > >
    > > Then no, there is no such easy thing for cloning controls, sorry!
    > >
    > > --
    > > Victor Garcia Aprea
    > > Microsoft MVP | ASP.NET
    > > Looking for insights on ASP.NET? Read my blog:
    > > http://obies.com/vga/blog.aspx
    > > My profile: http://aspnet2.com/mvp.ashx?vga
    > >
    > > "Neo" <> wrote in message
    > > news:u$...
    > > > Hi,
    > > >
    > > > I want to place two buttons on the page. These two button are

    > > identical.Is
    > > > there a way to duplicate a button? or I have to assign all properties of

    > > one
    > > > button to another.
    > > >
    > > > Thanks in advance.
    > > >
    > > > Neo
    > > >
    > > >

    > >
    > >

    >
    >
    >
    Donald Welker, Aug 19, 2004
    #4
  5. Neo

    David Jessee Guest

    You'll need to delve into System.Reflection for that one.

    Look at the PropertyInfo class. Make sure they have differentID's though


    "Neo" <> wrote in message
    news:u$...
    > Hi,
    >
    > I want to place two buttons on the page. These two button are

    identical.Is
    > there a way to duplicate a button? or I have to assign all properties of

    one
    > button to another.
    >
    > Thanks in advance.
    >
    > Neo
    >
    >
    David Jessee, Sep 20, 2004
    #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. Replies:
    2
    Views:
    456
    Kevin Jones
    Aug 25, 2006
  2. hummh
    Replies:
    0
    Views:
    331
    hummh
    Aug 9, 2007
  3. Grant Harmeyer

    DataView.Sort causing duplicate entries in a DataGrid control

    Grant Harmeyer, Jun 15, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    161
    Grant Harmeyer
    Jun 15, 2004
  4. Ramakrishna

    listbox control removing duplicate items

    Ramakrishna, Nov 4, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    149
    Ramakrishna
    Nov 4, 2003
  5. Ed Klein

    How to duplicate a user control on a page?

    Ed Klein, Dec 5, 2003, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    364
    Ed Klein
    Dec 5, 2003
Loading...

Share This Page