Custom attributes in ASP.NET web forms HTML tag

2020-02-12 21:29发布

I am using ASP.NET webforms on the .NET 3.5 framework. How can I achieve a custom attribute in the HTML tag such as:

<HTML lang="en">

I want to achieve this in the code behind on a common inherited base page. The attribute value would dynamically set based on a session value everytime a page is loaded.

Late addition: I want to achieve this without any ASP page changes to script tags if possible

8条回答
Explosion°爆炸
2楼-- · 2020-02-12 21:56

Question is old but may be of use to someone. Here's what I did..

In code behind :

  public string langName
            {
                get
                {
                    return Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
                }
            }

In ASP.NET PAGE

<html lang="<%= langName %>">

I was working with Local Resources for each language & cultures also so I found this to be a better solution.

Also, because I was using a Master page, I had to add it only once.

查看更多
兄弟一词,经得起流年.
3楼-- · 2020-02-12 21:58

I use this to set the language I'm using in my code:

<html xmlns="http://www.w3.org/1999/xhtml" lang="<%= System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName %>">
查看更多
登录 后发表回答