Understanding the runat server attribute

前端 未结 4 860
时光取名叫无心
时光取名叫无心 2020-12-03 02:13

I\'m really new to ASP.NET. I was just checking out a default ASP.NET web application. It comes by default with a few pages (Default.aspx, About.aspx etc).

I notice

4条回答
  •  盖世英雄少女心
    2020-12-03 03:12

    The head element contains a runat="server" attribute, which indicates that it is a server control (rather than static HTML). All ASP.NET pages derive from the Page class, which is located in the System.Web.UI namespace. This class contains a Header property that provides access to the page's region. Using the Header property we can set an ASP.NET page's title or add additional markup to the rendered section. It is possible, then, to customize a content page's element by writing a bit of code in the page's Page_Load event handler.

    ' Programmatically add a  element to the Header
    
    Dim keywords As New HtmlMeta()
    keywords.Name = "keywords"
    keywords.Content = "master page,asp.net,tutorial"
    Page.Header.Controls.Add(keywords)
    

    For more info see Specifying Meta Tags in ASP.NET with VB.NET.

提交回复
热议问题