In asp. net2.0, the CS code is used to dynamically specify the information in the head in the aspx page.

Source: Internet
Author: User

When you use asp.net for web development, the information in

Protected override void OnLoad (EventArgs e)
{
/* Add the following dynamically added code here */
Base. OnLoad (e );
}

The following is the dynamically added code.

/* Dynamically Add a style sheet */

HtmlLink link = new HtmlLink ();

Link. Attributes. Add ("type", "text/css ");

Link. Attributes. Add ("rel", "stylesheet ");

Link. Attributes. Add ("href ","~ /Main.css ");

This. Header. Controls. Add (link );

 

/* Dynamically Add a style */

Style style = new Style ();

Style. ForeColor = System. Drawing. Color. Navy;

Style. BackColor = System. Drawing. Color. LightGray;

This. Header. StyleSheet. CreateStyleRule (style, null, "body ");

 

/* Dynamically add Meta */

HtmlMeta = new HtmlMeta ();

Meta. Name = "keywords ";

Meta. Content = "Your keywords here ";

This. Header. Controls. Add (meta );

 

Meta = new HtmlMeta ();

Meta. Name = "company ";

Meta. Content = "microsoft ";

This. Header. Controls. Add (meta );

 

Meta = new HtmlMeta ();

Meta. Name = "date ";

Meta. Content = DateTime. Now. ToString ("yyyy-MM-dd ");

Meta. Scheme = "YYYY-MM-DD ";

This. Header. Controls. Add (meta );

 

 

/* Dynamically add js files */

HtmlGenericControl si = new HtmlGenericControl ();

Si. TagName = "script ";

Si. Attributes. Add ("language", "javascript ");

Si. Attributes. Add ("type", "text/javascript ");

Si. Attributes. Add ("src", "status. js"); // note the path writing method.

This. Page. Header. Controls. Add (si );

 

In this way, if you view the source code on a page that inherits the BasePage of the base class, you can find that the information added to the head of each page is the same! Haha, isn't that nonsense? It's not the same. It's still useless!

It took me a long time to debug the js Code. All the debugging was successful! It turned out to be a hit when I went to work on Saturday. The problem was solved, so I felt a lot better!

 

Test environment: vs2005

Self-perception has nothing to do with the test environment. It is estimated that only js file calls may be affected, because the type attribute is rarely written in <script>, if the type attribute is removed from vs2005, a validation error may occur, but the effect and function are not affected!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.