了解RUNAT服务器属性 [英] Understanding the runat server attribute

查看:278
本文介绍了了解RUNAT服务器属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很新的ASP.NET。我只是检查出了默认的ASP.NET Web应用程序。它配备默认了几页(Default.aspx的,About.aspx等)。

我注意到,Site.master母文件是我创造我的网页主要布局文件。
但我也注意到,标签有一个 =服务器属性。

我知道这个标签在中所使用; ASP:XXX> 标签,但为什么在< HEAD> 标记???

此外,当我删除该属性,那么所有的样式从网页消失了。所以appearently它做一些事情。我只是不明白究竟它做...

那么,为什么它在那里,在一个HTML标签...?我看不出有什么code应在服务器上运行...

 <头=服务器>
    <标题>喂< /标题>
    <链接HREF =〜/风格/的site.css的rel =stylesheet属性类型=文/ CSS/>    <! - 这部分在服务器上运行。那么,为什么头标记
         还需要中用runat = server的? - >
    < ASP:的ContentPlaceHolder ID =HeadContent=服务器>
    < / ASP:&的ContentPlaceHolder GT;
< /头>


解决方案

头元素包含一个 =服务器属性,这表明它是一个服务器控件(而不是静态的HTML)。所有的ASP.NET页面从Page类,它位于System.Web.UI命名空间派生。这个类包含了Header属性,提供了访问该页面的区域。使用Header属性我们可以设置一个ASP.NET页面的标题或添加额外的标记来呈现的部分。这是可能的,那么,通过在页面的的Page_Load 事件处理程序编写了一下code的自定义内容页的元素。

 '编程添加<&荟萃GT;元素页眉昏暗的关键字作为新HtmlMeta()
keywords.Name =关键词
keywords.Content =母版页,asp.net,教程
Page.Header.Controls.Add(关键字)

<一个href=\"http://www.asp.net/web-forms/tutorials/master-pages/specifying-the-title-meta-tags-and-other-html-headers-in-the-master-page-vb\">http://www.asp.net/web-forms/tutorials/master-pages/specifying-the-title-meta-tags-and-other-html-headers-in-the-master-page-vb

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 noticed that the Site.master file is the file where i create the main layout for my pages. But i also noticed that the head tag has a runat="server" attribute.

I know this tag is used in <asp:XXX> tags, but why in a <head> tag???

Also, when i remove that attribute, then all of the styles are gone from the webpage. So appearently it's doing something. I just don't understand what its exactly doing...

So why is it there, on an HTML tag...??? I don't see any code in there that should be run on the server...

<head runat="server">
    <title>Hallo</title>
    <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />

    <!-- This part is run on the server. So why does the head tag
         also need a runat=server ?? -->
    <asp:ContentPlaceHolder ID="HeadContent" runat="server">
    </asp:ContentPlaceHolder>
</head>

解决方案

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 <meta> element to the Header

Dim keywords As New HtmlMeta()
keywords.Name = "keywords"
keywords.Content = "master page,asp.net,tutorial"
Page.Header.Controls.Add(keywords)

http://www.asp.net/web-forms/tutorials/master-pages/specifying-the-title-meta-tags-and-other-html-headers-in-the-master-page-vb

这篇关于了解RUNAT服务器属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆