views:

94

answers:

3

what is difference if we write script manager with end tag and script manager as a empty tag in this format :

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

and script manager as a empty tag.

 <asp:ScriptManager runat="server"/>

I found this question in some interview question's book.. plez give me some knowledge about it or give me any link..

+1  A: 

No difference, both are completely equivalent (whatever the tag, by the way).

Timores
+1  A: 

If you don't need to insert any javascript, then using the empty tag uses less bytes since it's a shorter way to do the same thing.

If you do need to add some javascript, then you'll have to use the 'end tag' version, since that's the only way to put script inside... between the opening and closing tags. eg:

    <asp:ScriptManager runat="server" ID="ScriptManager1">
       <Scripts>
         <asp:ScriptReference Path="sample.js" />
       </Scripts>
    </asp:ScriptManager>

I tend to use the 'empty' tag version myself, I think it looks a bit neater and clutters up the source less.

See this: http://www.wrox.com/WileyCDA/Section/Using-the-ASP-NET-AJAX-ScriptManager.id-305492.html for more details.

HTH, Lance

Lanceomagnifico
+2  A: 

With your example they are equivalent, with the exception that you cannot add any children to the self-closing version, which is fine if you're doing it programmatically.

Note that this isn't specific to this control at all, it applies to almost any ASP.Net control (some have to have children to be valid). For example:

<asp:DropdownList id="bob" runat="server" />

This is fine if you're databinding or manually adding items to the list in code, otherwise you'd need <asp:ListItem /> elements in the page...the short answer is it's just a more clean/concise way to write a tag that doesn't need any children.

Nick Craver