First time here? Check out the site's "greatest hits" or read a post from the archives. Feel free to leave a comment or ask a question, and consider subscribing to the latest posts via RSS or e-mail. Thanks for visiting!
« ASP.NET Internationalization, Globalizat... | Main | Steven Frank's Blogging Anthem »

Has anyone given any thought on how to programmatically modify/add the dir= attribute to the HTML or BODY tags when the Thread's Culture in ASP.NET is a Right To Left language?

This doesn't work reliablity, as ASP.NET may batch up controls into an HtmlLiteralControl...often, not always, the body (or html) tag can't be found.  This depends on how ASP.NET decided to parse the control tree for a particular page.  Additionally, there doesn't seem to be anything in CultureInfo that would help me decide what languages are right to left...

If I can reliably get ahold of the HTML control and BODY tags and add this attribute, I'm good.

/* Doesn't work reliably */

HtmlGenericControl bodytag = (HtmlGenericControl)FindControl("body");
if (Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName == "ar")
   bodytag.Attributes["dir"] = "rtl";
else
   bodytag.Attributes["dir"] = "rtl";

Tracked by:
"Making the ASP.NET Mobile Controls render RTL languages" (Scott Hanselman's Com... [Trackback]


Thursday, March 27, 2003 2:59:09 AM (Pacific Standard Time, UTC-08:00)
Have you tried applying the runat and ID tags to the body (and/or head) tag itself? You shouldn't need to do a Page.FindControl then...

John St. Clair
Thursday, March 27, 2003 11:57:21 AM (Pacific Standard Time, UTC-08:00)
Maybe you could put some code in your page to emit/register some client-side javascript to set this attribute as you please. Something like:
Sergio Pereira
Thursday, March 27, 2003 1:00:30 PM (Pacific Standard Time, UTC-08:00)
Both of these are great ideas...the 1st is good, but requires a runat=server for every page on the site. I like it though.

Wednesday, April 02, 2003 4:52:26 PM (Pacific Standard Time, UTC-08:00)
To add attributes to <body> I do a bit of butching by overriding OnPreRender for page and using regular expressions. Works quite well (you can add event handler instead but overriding was easier for me as I have base class for all pages).

Wednesday, April 02, 2003 4:54:21 PM (Pacific Standard Time, UTC-08:00)
Wow! Cut'n'paste code from Visual Studio, obviously, was not a very bright idea :-P
Comments are closed.

Contact

Sponsors

Hosting By

On this page...

Tags

Calendar

<November 2008>
SunMonTueWedThuFriSat
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

Archives

Google Ads