J
J R M
I've developed a custom control (it's basically a drop-down list and
then a couple of textboxes to include meta-data for the selection) that
I'm embedding into another custom control (the idea is to allow a
dynamic number of control1 to appear in control2). Everything renders
correctly, however I could never retrieve data on postback from my
embedded controls. Upon closer inspection, all of the embedded
controls output without any "name" attributes on them, so the postback
can't find the data. I've got all of my controls implementing
INamingContainer which I thought would fix things, but it doesn't.
Furthermore, if I specify ID's for the embedded controls, they DO get a
"name" attribute, but it doesn't conform to the typical naming
heirarchy that aspnet uses to label controls, so I'm still not seeing
my data on postback. I guess I could try writing some code to search
for the goofy names to try to retrieve my data, but that feels like a
clumsy, easily breakable hack.
So my primary question is: Is it possible to embed custom controls
within custom controls?
Lead up to question 2: As I was playing with this, I wondered if
perhaps my array of embedded controls was to blame, so I tried creating
just a single instance of my embedded control and the same thing (no
'name' attr) happened. Just for kicks, I tried generating an array of
stock TextBox controls and by golly, the same thing happened--the
textboxes rendered, but the 'name' attribute was empty. (BTW, both the
custom control and the textbox array were declared as a class instance
variables and initialized in "OnInit"),
So question #2 is: Is it possible to have a dynamically-sized
collection of controls within a custom control? Or am I going to have
to "fix" this by creating individual instances of everything within a
single custom control?
Let me know if I can provide any other info. Thanks for any advice.
Jay
then a couple of textboxes to include meta-data for the selection) that
I'm embedding into another custom control (the idea is to allow a
dynamic number of control1 to appear in control2). Everything renders
correctly, however I could never retrieve data on postback from my
embedded controls. Upon closer inspection, all of the embedded
controls output without any "name" attributes on them, so the postback
can't find the data. I've got all of my controls implementing
INamingContainer which I thought would fix things, but it doesn't.
Furthermore, if I specify ID's for the embedded controls, they DO get a
"name" attribute, but it doesn't conform to the typical naming
heirarchy that aspnet uses to label controls, so I'm still not seeing
my data on postback. I guess I could try writing some code to search
for the goofy names to try to retrieve my data, but that feels like a
clumsy, easily breakable hack.
So my primary question is: Is it possible to embed custom controls
within custom controls?
Lead up to question 2: As I was playing with this, I wondered if
perhaps my array of embedded controls was to blame, so I tried creating
just a single instance of my embedded control and the same thing (no
'name' attr) happened. Just for kicks, I tried generating an array of
stock TextBox controls and by golly, the same thing happened--the
textboxes rendered, but the 'name' attribute was empty. (BTW, both the
custom control and the textbox array were declared as a class instance
variables and initialized in "OnInit"),
So question #2 is: Is it possible to have a dynamically-sized
collection of controls within a custom control? Or am I going to have
to "fix" this by creating individual instances of everything within a
single custom control?
Let me know if I can provide any other info. Thanks for any advice.
Jay