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)
我有一个表单有一些类似的控件,父表包含属性,但孩子实际上有html控件。如何使用父类中的“子”控件设置我的getter / setter? (Webforms - fyi)
I found the below via search, and what I'm looking for is the inverse
我通过搜索找到了下面的内容,而我正在寻找的是相反的
Getting value of a property in Parent User control from a Child user control
从Child用户控件获取父用户控件中的属性值
Edit:
I should have tried this early on, but instead found it "fun" to explain this crazy situation. The below is what worked @ 100%
我应该早点尝试过,但是发现解释这种疯狂的情况很有趣。以下是@ 100%的效果
Get
Return DirectCast(Page.FindControl("lblCASE_NUMBER"), HtmlContainerControl).InnerHtml
End Get
2 个解决方案
#1
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.
1 - 将代码放在父级并在每个子级上创建属性,以便可以访问控件的值。
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.
2 - 创建一个抽象类来放置您不想复制的代码,并使您的所有子代都继承它。您需要在此类中创建公共对象作为“受保护的抽象ObjectName”,并在您的子项中将它们设置为“受保护的覆盖ObjectName”。此选项将提供最少的代码来写,但它“强迫”您理解继承。
#2
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.
如果我理解正确,则在另一个usercontrol(父级)中有一个usercontrol(child),并且您需要从父级中访问子属性。
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.
如果这是正确的,您需要做的就是在子项中创建属性或方法,就像在任何其他类中一样。而不仅仅是从父母那里使用它们。
#1
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.
1 - 将代码放在父级并在每个子级上创建属性,以便可以访问控件的值。
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.
2 - 创建一个抽象类来放置您不想复制的代码,并使您的所有子代都继承它。您需要在此类中创建公共对象作为“受保护的抽象ObjectName”,并在您的子项中将它们设置为“受保护的覆盖ObjectName”。此选项将提供最少的代码来写,但它“强迫”您理解继承。
#2
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.
如果我理解正确,则在另一个usercontrol(父级)中有一个usercontrol(child),并且您需要从父级中访问子属性。
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.
如果这是正确的,您需要做的就是在子项中创建属性或方法,就像在任何其他类中一样。而不仅仅是从父母那里使用它们。