开发者

ASP.NET - what is the meaning of <%@ and <asp:Panel?

In the generated asp.net code from visual web developer 2010, I see the following code:

<%@ Control Language="C#" ClassName="Header" %>

    <asp:Panel ID="Panel1" runat="server">
        <img alt="xxx" 
            src="Images/bird.jpg" 
            width="800" height="110"/>
    </asp:Panel>
    <asp:Panel id="menuPanel" runat="server">
        <a href="1.aspx">Home</a> |
        <a href="2.aspx">Titles</a> |
        <a href="3.aspx">Authors</a&g开发者_StackOverflow社区t; |
        <a href="4.aspx">Publishers</a>
    </asp:Panel>
  1. What is the meaning of <%@ in asp.net?
  2. What is the meaning of <asp:Panel?

I see other examples, <asp:Button <asp:Label, etc.

Thank you


ASP.NET server instructions are enclosed by angled brackets: <% ... %>; they tell ASP.NET to process their contents before sending a page to the client's browser.

@ identifies a directive, which do a variety of things but usually provide some instructions about what to do with the .aspx or .ascx file: Page and Control are two of the most commonly-used directives.

<asp:Panel> is an ASP.NET WebControl. Web controls are server-side representations of HTML elements. They allow you to manipulate the page in a code-behind file that's executed on the server before being delivered to the client's browser.

For example, ASP.NET renders Panel tags as <div> elements, and renders Button tags as <input> elements.


<asp:panel is a Panel

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.panel.aspx

<asp:button is a button

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.aspx\

<@% Creates an association between a tag prefix and a custom control

http://msdn.microsoft.com/en-us/library/c76dd5k1.aspx


1) The <%@ is used to reference a user control that you can add to your page.
2) The <asp:Panel is just a container, in HTML it gets generated as a div. The panel has other properties, but in the end it is just a container.

Overall, anything with <asp is some form of ASP.NET web control.


Tags starting with asp:SomeName declare server controls. A server control is simply a control that is understood by the server. From w3schools:

HTML server controls are HTML tags understood by the server.

HTML elements in ASP.NET files are, by default, treated as text. To make these elements programmable, add a runat="server" attribute to the HTML element. This attribute indicates that the element should be treated as a server control. The id attribute is added to identify the server control. The id reference can be used to manipulate the server control at run time.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜