q0987
q0987

Reputation: 35982

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> |
        <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

Upvotes: 4

Views: 3347

Answers (4)

Jeff Sternal
Jeff Sternal

Reputation: 48583

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.

Upvotes: 5

Oren A
Oren A

Reputation: 5880

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.

Upvotes: 1

Dustin Laine
Dustin Laine

Reputation: 38503

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.

Upvotes: 1

Related Questions