SoFunction
Updated on 2025-03-07

Solution to the CSS failure in asp.net2.0

1. The CSS file path is incorrect
This problem is a basic problem in web development. Generally, such a problem occurs when using relative paths, or the style file is written in the master page, and this problem occurs when the content page and the master page are not in the same level directory. At this time, you need to be clear about the rules of relative paths in the web. If you are not clear, you can use the absolute path to write it to know if it is a problem with the path.

2. CSS rules written incorrectly
No one can help you with this question, so you can only learn the relevant knowledge of CSS by yourself.

3. File encoding problem
Sometimes, CSS styles are valid in aspx files, but are invalid in separate files. If such problems are not path problems, they are caused by encoding problems. You can open the CSS file in Notepad and save it as ANSI format or UTF-8 format.

4. Permission issues
A common phenomenon in this case is that the style is invalid before logging in, but it is only valid after logging in. This is caused by a typical permission problem. This problem occurs because all files are configured not to allow anonymous access. The solution is to configure the <location> tag to configure the style file to allow anonymous access. For example:

Copy the codeThe code is as follows:

<configuration>
<location path="The name of the folder or file path that allows anonymous access">
      <>
         <authorization>
            <allow users="?"/>
         </authorization>
      </>
   </location>
</configuration>

5. Click button style fails
The most typical reason for this situation is that there are statements like this in the button click event. Since 2.0 uses the http:///TR/xhtml1/DTD/ document type definition by default, it requires that there cannot be any output in front of <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/">. The solution to this problem is to use ClientScriptManager to output, or use Literal control to output content.

6. The style that works in the 2.0 fails
This problem is generally still caused by xhtml1. Since the style rules of http:///TR/xhtml1/DTD/ are different from those in the past, such as adding units, such as width:200; now it needs to be written as width:200px; the solution to this problem is to clearly add units.

7. The script set style is invalid
Since there are units required, when setting the value of the object style, you still need to add units, such as = "200px". The following code is invalid in Firefox (Don't complain about Firefox trouble)

Copy the codeThe code is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/">
<html xmlns="http:///1999/xhtml">
<head>
  <script type="text/javascript">
  //<![CDATA[
  function SetHeight()
  {
    ("x").="200"
  }
  //]]>
  </script>
</head>
<body>
<div style="background:#DDD;height:auto;">Test</div>
<input type="button" value="SetHeight()" />
</body>
</html>

Although the above is normal in IE, there will be problems in Firefox. The correct way to write it is

Copy the codeThe code is as follows:

("x").="200px"