开发者

<asp:XXXX > vs <%# %>/<%@ %>

I'm starting to learn ASP.NET and going through the tutorial videos on www.asp.net. I understand the basic concept of web application frame works like ASP/PHP/ASP.NET. HTML/XHTML is created with special tags that the server knows to read and replace with content. I did a little bit with ASP during a summer internship back in the 90's.

Yet with the few examples of ASP.NET I've seen so far it seems ASP.NET has two types of server interpreted tags.

Most of the time I see <asp:XXXX > tags such as

<asp:ContentPlaceHolder ID="Hea开发者_开发技巧dContent" runat="server">
</asp:ContentPlaceHolder>

but I also see regular ASP tags like

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="TailspinSpyWorks.SiteMaster" %>

What is the difference between these two tag formats? Both are interpreted by the server correct? Why would I use one over the other?


The <%@ %> tags are called directives, they're used by the compilers for compiling the page or user control.

The <asp:....> tags are just ASP server controls (other prefixes may be user controls, etc) they're components in the page itself.

From your title <%# %> is again something different, it's called a data binding expression, that's the binding syntax used for binding whatever's inside, for example: <%# Eval("property %>.

There's also <%= %> which is equivalent to Response.Write() for outputting content directly in the page, and there's a <%: %> version that also does html encoding for sanitized output in .Net 4.0.

All of these simply have different purposes, so you're not usually choosing between them (though some cases certainly overlap), they're just used in different situations.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜