When should I use a Localize control instead of a Literal?

前端 未结 2 2068
隐瞒了意图╮
隐瞒了意图╮ 2021-02-12 06:09

I recently became aware of the System.Web.UI.WebControls.Localize control in a lab for the ASP.NET 4.0 MCTS certification course. The purpose of this control is unclear to me.

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-12 06:43

    I appreciate this has already been marked as answered, but here is another way to look at it.

    is used to specify a Resource defined item, which forces the IDE to display some specified text, and still allows it to resolve at runtime, to the language of the website.

    This may be useful for the development of a site where the content of the site is actually in a different language. So you would be able to be an English-speaking programmer, creating a website in Turkish, and still know what a is supposed to without having to learn Turkish.

    So as an example:

         
       Price
    
    

    Now, if my default Label.resx was translated into Turkish, the Labels.resx mapping would be:

    Key="Price"
    Value="fiyat"
    

    At design time, the IDE would display Price (as the inner text of the element is Price) but the actual live view of the page in a web browser, would resolve to fiyat.

    Therefore:

    Price

    Becomes rendered as:

    fiyat

    But in the IDE Designer, this would be displayed as "Price".

    The difference with labels, is that will resolve to fiyat in both the IDE Designer and at run-time.

提交回复
热议问题