views:

97

answers:

2

I have a form that has a few similar controls and the parent contains the properties, but the child actually has the html controls. How could I setup my getters/setters using the "child" controls in the parent class? (Webforms - fyi)

I found the below via search, and what I'm looking for is the inverse

http://stackoverflow.com/questions/463938/getting-value-of-a-property-in-parent-user-control-from-a-child-user-control

Edit:

I should have tried this early on, but instead found it "fun" to explain this crazy situation. The below is what worked @ 100%

Get
  Return DirectCast(Page.FindControl("lblCASE_NUMBER"), HtmlContainerControl).InnerHtml
End Get
+1  A: 

If I understood you correctly you have one usercontrol (child) inside another usercontrol(parent) and you need to access the child properties from within the parent.

If this is correct all you need to do is either create properties or methods in the child as you would in any other class. Than just use them from the parent.

Sergio
Understood, i was trying to reduce the duplication if possible ... is it possible to get just a few controls from the parent and yet have the child render it's html appended?
Toran Billups
Could you be a little more explicit? I am not understanding what you need...
Sergio
Sure - I'm doing some ajax to get html generated from the server side. All the forms I'm getting have the same 4 html controls so to keep everything DRY i implemented a subset of the view interface in the parent. The parent then does all the "work" for each child as it's the same coding w/ the ..
Toran Billups
exception of the "getbyid" and "update" methods that are defined in a custom presenter. But as the parent takes any presenter that meets the contract (interface for the parent presenter) it can make the calls in the parent (again - ZERO code in the child), but the one issue remains ... i dont' want
Toran Billups
to dump the properties into each form if the parent can define them 1x
Toran Billups
it appears the simple page.findcontrol was all I needed ... sorry to get you involved but I really appreciate the help!
Toran Billups
A: 

Follwing up on the comments:

Ok, so if i understood correctly, you want to have the controls on the usercontrols but the code on the parent(because you don't want to duplicate code).

You have 2 ways of doing this:

1 - Place your code at the parent and create properties on each child so you can access the values of the controls.

2 - Create an abstract class to place the code you don't want to duplicate and make all your childs inherit from it. you will need to create the common objects at this class as "protected abstract ObjectName" and in you childs set them as "protected override ObjectName". This option will give the least code to write but it "forces" you to understand inheritance.

Sergio