Ticket T356223
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

How to colorize (make red) the asterisk symbol accompanying captions of required fields

Not able to get DetailViewItem from LayoutItemTemplateContainer

created 9 years ago

Hi,

We are using XAF Persistent object and we want to change asterisk(*) instead of default image for required fields.I follow we below ticket but not able to get "DetailViewItem" in LayoutItemTemplateContainer object.

https://www.devexpress.com/Support/Center/Question/Details/Q296200
Code is below:

C#
protected override Control CreateCaptionControl(LayoutItemTemplateContainer templateContainer) { Control result = null; PropertyEditor editor = templateContainer.DetailViewItem.DetailViewItem as PropertyEditor; if (editor != null) { if (editor.MemberInfo.FindAttribute<RuleRequiredFieldAttribute>() != null) { Table table = new Table(); table.Rows.Add(new TableRow()); table.Rows[0].Cells.Add(new TableCell()); table.Rows[0].Cells.Add(new TableCell()); Literal anchor = new Literal(); anchor.Text = string.Format("<span title='{0} Is Required' style='color:red'>*</span>", templateContainer.DetailViewItem.Caption); table.Rows[0].Cells[0].Controls.Add(anchor); Control baseControl = base.CreateCaptionControl(templateContainer); table.Rows[0].Cells[1].Controls.Add(baseControl); result = table; } } if (result == null) { result = base.CreateCaptionControl(templateContainer); } return result; }

bold part in above code is giving error.

Please help I tried other link but not working.

Answers approved by DevExpress Support

created 9 years ago (modified 9 years ago)

Hello Deepak,

You attempted to use code that was written many years ago. Usually, it is not a good idea to copy such old code "as is" and, instead, it is often better to look for alternative solutions or even built-in options added in recent product versions.
Here you should use different members of the LayoutItemTemplateContainer class to obtain caption information. For instance, templateContainer.Model.ViewItem.Caption.
Also, I want to inform you that in the latest XAF version, it is possible to easily provide the * character for required fields: https://community.devexpress.com/blogs/eaf/archive/2015/11/24/xaf-validation-module-enhancements-for-windows-and-the-web-coming-soon-in-v15-2.aspx

    Show previous comments (9)
    Dennis Garavsky (DevExpress) 9 years ago

      Hello Deepak,

      To process your recent post more efficiently, I created a separate ticket on your behalf: T357302: Difficulties when providing a custom image. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates. Please take special note that the approach from this help article is supposed to be used with the latest v15.2.7.

        Hi Dennis,

        How we can change asterisk to red color for required field instead of black default color in above post?
        Please provide any sample for v15.2.

        Dennis Garavsky (DevExpress) 9 years ago

          Hello Deepak,

          To process your recent post more efficiently, I created a separate ticket on your behalf: T359882: How to color (make red) the asterisk symbol accompanying required fields. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates. As far as I understand, you need a solution for ASP.NET only, correct?

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.