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 2 1849
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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:...
|
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...
|
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:
...
|
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...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |