Search code examples
.netasp.netscript-tag

How do I end script tags?


I'm pretty new to web programming, reading a book on ASP.NET, and I notice the author does this;

<asp:ScriptManager ID="ScriptManager1" runat="server"/>

Instead of what Visual Studio does, which is this;

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

Is the first way of doing it an acceptable and multi-browser compatible shortcut?


Solution

  • Either way is acceptable, and it doesn't affect browser output, because the asp:ScriptManager tag is processed on the server-side.

    That being said, it's a matter of preference which style you use. There are some tags that have nested tags which require you to use the second style.

    However, if that is not the case, then semantically, the first style is known as a self-closing element and has the same semantic meaning in ASP.NET as the second syntax.

    I would recommending learning the distinction between server-side tags and client-side tags, because while similar in syntax, they can have very different results (for example, self-closing script tags in browsers typically don't work when using third-party libraries).