Multiple Composite Control Instances

Discussion in 'ASP .Net Building Controls' started by Russ, Sep 17, 2003.

  1. Russ

    Russ Guest

    I'm developing a composite control and one of the things
    I've run into is how to support being able to put multiple
    instances of my control onto a web form. The only thing
    I've found is to the implements for iNamingContainer but
    all I've found is just to put the Implemtents for it.
    Nothing if I need to do anything else

    I've tried that and still nothing chnages. Do I need to
    handle the uniqie naming of items in my control myself?

    Anyone point to any good articles?

    Thanks
    Russ, Sep 17, 2003
    #1
    1. Advertising

  2. "Russ" <> wrote in message
    news:643601c37d47$5b9afda0$...
    > I'm developing a composite control and one of the things
    > I've run into is how to support being able to put multiple
    > instances of my control onto a web form. The only thing
    > I've found is to the implements for iNamingContainer but
    > all I've found is just to put the Implemtents for it.
    > Nothing if I need to do anything else
    >
    > I've tried that and still nothing chnages. Do I need to
    > handle the uniqie naming of items in my control myself?
    >
    > Anyone point to any good articles?


    A composite control must implement INamingContainer. INamingContainer is
    just a marker interface. There is no code for you to implement.
    --
    John Saunders
    Internet Engineer
    John Saunders, Sep 17, 2003
    #2
    1. Advertising

  3. Russ

    Russ Lazarek Guest

    That's the same information I've read but what does that do? I've read
    that and placed that in but it doesn't seem to do anything.

    The problem I'm having is that the controls that are placed in the
    composite controls are assigned IDS when I add them to the control. I
    need to set the ID so I can reference in javascript. But when I do that
    and place 2 instacnes of the control onto my web form, I wind up with 2
    controls named the same for every control on my composite control.

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Russ Lazarek, Sep 17, 2003
    #3
  4. "Russ Lazarek" <> wrote in message
    news:%...
    > That's the same information I've read but what does that do? I've read
    > that and placed that in but it doesn't seem to do anything.
    >
    > The problem I'm having is that the controls that are placed in the
    > composite controls are assigned IDS when I add them to the control. I
    > need to set the ID so I can reference in javascript. But when I do that
    > and place 2 instacnes of the control onto my web form, I wind up with 2
    > controls named the same for every control on my composite control.


    You should not set the ID. Instead, pass control.ClientID to JavaScript so
    that it knows what the changed ID is.
    --
    John Saunders
    Internet Engineer
    John Saunders, Sep 17, 2003
    #4
  5. Russ

    Russ Lazarek Guest

    But if I don't assign an ID to the control when it is created, the
    control when rendered on the HTML page does not have any ID or name
    field. How does it get named? I'm creating controls in the composite
    both by DIMing them and adding them to the controls collection as well
    as creating them manually and writing out the tags to the writer in the
    render.


    As I totally missing something? Is there any example you know of that
    you can point me to.

    Thanks

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Russ Lazarek, Sep 17, 2003
    #5
  6. "Russ Lazarek" <> wrote in message
    news:...
    > But if I don't assign an ID to the control when it is created, the
    > control when rendered on the HTML page does not have any ID or name
    > field. How does it get named? I'm creating controls in the composite
    > both by DIMing them and adding them to the controls collection as well
    > as creating them manually and writing out the tags to the writer in the
    > render.
    >
    >
    > As I totally missing something? Is there any example you know of that
    > you can point me to.


    Yes, you are. :)

    In CreateChildControls, when you create a child control, give it an
    appropriate ID, like "btnOk". When you add it to your Controls collection,
    the ClientID property will be changed to have a prefix, making in unique.
    Pass this ClientID to JavaScript instead of passing the ID.

    I'm sorry, but I don't have any VB.NET examples to show you. I will
    recommend my favorite book on controls, though:

    "Developing Microsoft® ASP.NET Server Controls and Components" from
    Microsoft Press, by Nikhil Kothari and Vandana Datye
    (http://www.microsoft.com/mspress/books/5728.asp).
    --
    John Saunders
    Internet Engineer
    John Saunders, Sep 17, 2003
    #6
  7. Russ

    Russ Lazarek Guest

    Thanks I actually have that book on order, just havn't gotten it yet.

    So basically it sounds like the way I'm creating controls in the render
    is totally wrong and instead I have to move everything to the
    createchild controls which I can do. One last question, in the render
    I'm currently attaching an event to an onclick event for an img tag, If
    I move that to createchildcontrol, how do I add that client side event
    to the control?

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Russ Lazarek, Sep 17, 2003
    #7
  8. "Russ Lazarek" <> wrote in message
    news:...
    > Thanks I actually have that book on order, just havn't gotten it yet.
    >
    > So basically it sounds like the way I'm creating controls in the render
    > is totally wrong and instead I have to move everything to the
    > createchild controls which I can do. One last question, in the render
    > I'm currently attaching an event to an onclick event for an img tag, If
    > I move that to createchildcontrol, how do I add that client side event
    > to the control?


    The exact same way you would in Render. control.Attributes["onclick"] =
    "script;return;"
    --
    John Saunders
    Internet Engineer
    John Saunders, Sep 17, 2003
    #8
  9. Hi Russ,

    I am sorry if there is any misunderstanding.

    As I understand, your last question is

    How to associate Client-Side Events with Server-Side Controls

    Based on my research and experience, the following Knowledge Base article
    is useful to you.

    http://support.microsoft.com/default.aspx?scid=kb;EN-US;318814

    Does it answer your question? If I have misunderstood your concern, please
    feel free to let me know.

    Best regards,

    Jacob Yang
    Microsoft Online Partner Support
    <MCSD>
    Get Secure! ¨C www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.
    Jacob Yang [MSFT], Sep 18, 2003
    #9
    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. sleigh
    Replies:
    1
    Views:
    2,658
    sleigh
    Feb 12, 2004
  2. John Wohlbier
    Replies:
    2
    Views:
    348
    Josiah Carlson
    Feb 22, 2004
  3. Replies:
    8
    Views:
    437
    James Stroud
    Jan 29, 2009
  4. Chad
    Replies:
    0
    Views:
    205
  5. Mike

    Composite vs non composite Controls

    Mike, Mar 10, 2005, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    244
    Sundararajan
    Mar 11, 2005
Loading...

Share This Page