AKD
AKD

Reputation: 3964

why to include runat="server" in ASP.NET

HI Guys
actually i was digging & quite confused from since i am working on Web with ASP.NET THAT whenever i need to use a server tag (control) like
<asp:Label ID="lblName" />
& then to make it as a programmable element, so that i could access it in behind code i must include runat = "server" but when if it must be included then how it will differ from normal HTML tag, i mean what is the exact reason to include runat = "server" & whats the different between general HTML tag & an ASP.NET tag without runat = "server" ?

Upvotes: 3

Views: 3678

Answers (1)

Guffa
Guffa

Reputation: 700910

When the markup code is parsed, everything is converted into server controls.

Any elements that are not tagged with runat="server" will just end up as a LiteralControl control with the HTML code as text.

For example, markup like this:

<div>
  <p>
    <span id="asdf" runat="server"> </span>
  </p>
</div>

will end up as the controls:

LiteralControl("<div><p>")
HtmlGenericControl("span") with id asdf
LiteralControl("</p></div>")

Upvotes: 3

Related Questions