asp.net - Does Request.Browser work always as expected? -


I have a passcode to add the correct CSS file to the "head" on a browser,

string browser name = request Browser.Browser; String Browser View = Request Browser.Version; Control Head = Page master. Fund Control ("Stu Head"); If {head = = "IE"} {if (browserVersion == "6.0") {Head.Controls.Add (New Little Control (" ")); } Else {head.Controls.Add (new literal control ("lift relay = 'style sheet' REC = 'stylesheet' href = 'home-IASSS' type = 'text / css' media = 'all' />) ); }} Else {head.Controls.Add (new literalControl ("& lt; link rel = 'stylesheet' rev = 'stylesheet' href = 'home.css' type = 'text / css' media = 'all' /> ; ")); }} Else {Response.Write ("link rel = 'stylesheet' rev = 'stylesheet' href = 'home.css' type = 'text / css' media = 'all' />); }

When I open my page in IE8, sometimes I look at Home.css, I should actually see Home-IECSS. I have ensured that the head is not empty. Not sure anybody has experienced such a thing appreciated any comments.

I wonder why you do not do it in the HTML section ... Many websites explain it .

  & lt ;! - [if IE] & gt; & Lt; Link rel = "stylesheet" type = "text / css" href = "all-ie.css" /> & Lt; [Endif] - & gt;  

  & lt; Link rel = "stylesheet" type = "text / css" href = "common.css" /> & Lt ;! - [if IE] & gt; & Lt; Link rel = "stylesheet" type = "text / css" href = "all-ie.css" /> & Lt; [Endif] - & gt; & Lt ;! - [If IE 6] & gt; & Lt; Link rel = "stylesheet" type = "text / css" href = "i.e.-6.0.css" /> & Lt; [Endif] - & gt; & Lt ;! - [If LT IE 6] & gt; & Lt; Link rel = "stylesheet" type = "text / css" href = "i.e.-5.0 + 5.5 css" /> & Lt; [Endif] - & gt;   

Just to indicate something on your code, how to learn a refactor and how to reuse the code.

  string browser name = requested Browser.Browser; String Browser View = Request Browser.Version; If (Head! = Blank) {if (browserName == "IE") {if (BrowserVersion == "6.0") AddCSS ("Home-IE6.css", Incorrect); ADCSS ("Home-IACSS", Incorrect); } And AddCSS ("home.css", incorrect); } And AddCSS ("home.css", is true);  

...

  Zero AddCss (string css file, bold type) {control head = page. Muster.FindControl ("stu head"); String css = string.format ("& lt; link rel = 'stylesheet' rev = 'stylesheet' href = '{0}' type = 'text / css' media = 'all' / & gt;", css file); If (Write) Answer CRS; CRS; other major. Control. Add (New Literal Control (CSS)); }  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -