Multiple Composite Control Instances

R

Russ

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
 
J

John Saunders

Russ said:
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.
 
R

Russ Lazarek

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.
 
J

John Saunders

Russ Lazarek said:
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.
 
R

Russ Lazarek

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
 
J

John Saunders

Russ Lazarek said:
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).
 
R

Russ Lazarek

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?
 
J

John Saunders

Russ Lazarek said:
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;"
 
J

Jacob Yang [MSFT]

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.
 

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

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top