Display attribute to label

Sep 10, 2013 at 11:01 AM
Got all this working however how do you wireup the display attribute of the model with a label on the form?

Cheers

Ismail
Coordinator
Sep 10, 2013 at 2:37 PM
Most of the time I'm using resources and in that case same resource is referenced in model (in DisplayAttribute) and in label/button/whatever control via ResourceExpression.

If you are not using resources then I think it is possible to use DynamicControl but this will require to keep a set of FieldTemplates and a call of EnableDynamicData + DataBind methods if not used inside DataBound controls such as FormView, GridView, Details View, etc. But I doubt that this is the best and frictionless way of wiring DisplayAttribute and label.

As a radical alternative you can inherit from Label and extend its Text property so it will pull DisplayAttribute based on type and property name of model.
Sep 10, 2013 at 5:00 PM
amanek,

Many thanks for the prompt reply. I took another route:
           //get all labels in main control of interest
            var labels = WebHelper.ControlsByTypeUsingAncestor<Label>(userDataCapture).Where(l=>l.AssociatedControlID!=string.Empty);

            foreach (var label in labels)
            {
                //i have used same textbox control name as model field name so can get display attribute via the MetadataSource object
                label.Text = msUserInformation.GetDisplayName(label.AssociatedControlID);
            }
All works nicely.

Many thanks for awesome and useful library.

Regards

Ismail
Coordinator
Sep 11, 2013 at 9:04 PM
Looks good and logical. Thanks for sharing.


2013/9/10 ismailm <[email removed]>

From: ismailm

amanek,

Many thanks for the prompt reply. I took another route:
           //get all labels in main control of interest
            var labels = WebHelper.ControlsByTypeUsingAncestor<Label>(userDataCapture).Where(l=>l.AssociatedControlID!=string.Empty);

            foreach (var label in labels)
            {
                //i have used same textbox control name as model field name so can get display attribute via the MetadataSource object
                label.Text = msUserInformation.GetDisplayName(label.AssociatedControlID);
            }
All works nicely.

Many thanks for awesome and useful library.

Regards

Ismail

Read the full discussion online.

To add a post to this discussion, reply to this email ([email removed])

To start a new discussion for this project, email [email removed]

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com