I have a User Control (named FormLayout
here) that generate form elements and divs in specific positioning and styles based on the fields defined in the parent.
The goal achieve the following, so that in Code Behind, I can access these form layout fields easily. (I want these fields to be defined in HTML so that there will be auto generated properties that allows them to be accessed directly in parent Code Behind.)
<FormLayout runat="server" ID="ucFormLayout" FormTitle="My Form" FormDescription="">
<FieldDropDown runat="server" ID="field1"></FormLayoutField>
<FieldTextBox runat="server" ID="field2"></FormLayoutField>
</FormLayout>
field1.LabelText = "my title";
field1.Data = "my data";
field1.Column = 2;
field1.Options = new Dictionary<string,string>();
class FormLayoutField {
public string LabelText {get;set;}
public string Data {get;set};
public int Column {get;set;}
}
class FieldDropDown:FormLayoutField {
public Dictionary<string, string> Options {get;set;}
}
class FieldTextBox:FormLayoutField {
public string Placeholder {get;set;}
}
In the FormLayout User Control, based on what are being set in the list of FormLayoutField
, it generates elements such as divs
or labels
with specific positioning, styles, and data. The FormLayoutField
are simply containers for data and layout settings to be used by the user control. They don’t need to control their own rendering.
How to implement such FormLayoutField
Controls so that they can be passed to the FormLayout
User Control in HTML, while also being accessable in the parent webform’s code-behind?