문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top