You know if you’re working with Repeater Controls you’re not able to access the controls the generic way (as far as I know). So we try to use const strings for most situations we have to work with strings in C#.
So I’ve made a class with const strings. They define the ID names of the Controls inside a repeater. That makes it possible to access the controls in a more generic way than using the plain strings in code. Example:
public class FormularRepeaterFieldIDs
{
public const string RubrikLiteral = "BuchungRubrikLiteral";
public const string RubrikDropDownList = "BuchungRubrikList";
public const string RubrikIdHiddenField = "BuchungRubrikIdHidden";
}
Which enables access like this (of course you could make a easier access wrapper for this):
Literal rubrikLiteral = (Literal)e.Item.FindControl(TimeExpressHelper.FormularRepeaterFieldIDs.RubrikLiteral);
rubrikLiteral.Visible = false;
Now I would also be cool to use the predefined IDs in Webforms Frontend code. It looks this at the moment:
<asp:Literal ID="BuchungRubrikLiteral" Text='<%#Eval("strRubrik")%>' runat="server" />
Would it be possible to make something like this?
<asp:Literal ID="<% FormularRepeaterFieldIDs.RubrikLiteral %>" Text='<%#Eval("strRubrik")%>' runat="server" />
You could probably make this work with a custom ExpressionBuilder. Something like:
with a ExpressionBuilder that uses
Reflectionand/or aCodeSnippetExpressionto read the value:and a web.config to register it to handle the
Constprefix:Or, you could take advantage of the existing ResourceExpressionBuilder, and make them resources instead of constants.