473,287 Members | 1,399 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Custom control within a custom control

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

May 18 '06 #1
2 1843
Figured this out. Sharing in case anyone else finds this useful.

I basically had to hotwire the controls to make this work via the
following steps:

1. Had to explicitly set all ID's for all embedded controls.
Implementing INamingContainer wasn't doing anything. Not sure why.

2. Had to implement IPostBackDataHandler and define the LoadPostData
method in both the parent and child controls in order to retrieve the
data for my custom child controls.

That's basically it, but this gets tricky because of life-cycle stuff.
The LoadPostData gets fired before the parent page's OnInit, so there
was a little dancing around I'd have to do to make sure all of my
objects were defined properly before I could really handle the postback
data. But it all seems to be working now.

Jay

May 26 '06 #2
You need to implement IPostBackDataHandler if you want to capture postbacks
in a Custom Server control.

Charlie
"J R M" <jm*******@gmail.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
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

Jun 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: microdevsolutions | last post by:
Hello I am using ASP.NET - I have written a Custom Control (to output some information) that has a public property declared. I have a user control that is a wrapper around the above custom...
4
by: BBFrost | last post by:
We have a data entry application written within Framework 1.0 that contains 20+ custom user controls. The controls overlay each other so that only one custom control is visible at a time. What...
19
by: Dales | last post by:
I have a custom control that builds what we refer to as "Formlets" around some content in a page. These are basically content "wrapper" sections that are tables that have a colored header and...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
11
by: Nick Gilbert | last post by:
Hi, How can I create a custom control which will wrap its content in a header and footer? eg: Is it possible to create a .NET user control which can surround other controls? eg:...
4
by: Jordan S. | last post by:
In a "standard" aspx page I can access the system cache (System.Web.Caching.Cache), like this: Cache = someObject; How can I access the same Cache from *within* a custom composite Web server...
7
by: Linda Liu[MSFT] | last post by:
Hi George, I have downloaded your sample solution and built it on my machine. I got a compilation error indicating that the type of "CustomResources" doesn't exist in the following xaml code: ...
3
by: RichB | last post by:
I would like to use the AJAX ASP.NET Accordion Control. Can I create a user control for the form and include this within a custom control which inherits from a Pane of the Accordion control? I...
4
by: =?Utf-8?B?UmljaEI=?= | last post by:
I am trying to create a project using the ASP.NET AJAX accordion control. I would like to dynamically add panes to the control with a form template added when the pane is added. I have tried...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.