• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 508
  • Last Modified:

ASP.NET control closing tags

Just a general curiousity.  Can anyone explain the point behind the closing tags in ASP.NET development?  It just seems kind of verbose when you can use the text property to show any text that needs to be displayed?  Always wondered about this one.
0
stretch73
Asked:
stretch73
  • 4
  • 2
1 Solution
 
David RobitailleAnalyst ProgrammerCommented:
That whole closing tag thing is all about being XHTML/XML "compilant"
I usually use this syntax when i dont have anything to put between the tags and i always use the text property.
<asp:textbox ID="textbox1" runat="server" test="text"/>
I use a closing tag only what is necessary, like when i do a dropdownlist with fixed items.
0
 
stretch73Author Commented:
I write my stuff the same way, but whenever I download demo code it seems like it's always written with the closing tag.  I figured there was some practical reason that I just hadn't heard of but I've never seen it addressed before.
0
 
David RobitailleAnalyst ProgrammerCommented:
well, i made a quick search because it was botherring myself for a wile too. i dident find anything
Maybe if you format a label like this the text proprety is not cached in the viewstate?
<asp:Label ID="Label1" runat="server" >label</asp:Label>
But, it may just be it`s just laziness from the demo`s author. Visual web developer format controls that way whenever you drag one in the page. They may have think it s easier to remove the closing tag that add it...
 
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jmoreno8238Commented:
Remember that ASP tags are just like HTML tags whats the point of doing a <br></br> if you can do a <br />.
It's just how the standard is.

You can have a
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
And a
<asp:TextBox ID="TextBox1" runat="server" />

It's just how the standard works. and there's no sense in altering this since asp tags just get preprocessed server side and afterwards translated into html tags anyway.
0
 
David RobitailleAnalyst ProgrammerCommented:
i think stretch73 was mor wondering about the
<asp:Label ID="Label1" runat="server" >label</asp:Label>
VS
<asp:Label ID="Label1" runat="server" text="label" />
but i agree, it<s just how the standard work...
0
 
stretch73Author Commented:
I was just wondering because back in the classic ASP days, I was taught to use as few opening and closing <% tags as possible because it basically meant another round trip to the server.  Seems to me that a closed tag like <asp:label text='label' runat='server' />  makes more sense.  It couldn't make that much difference or I'm sure they'd specify which was better.  Thanks for the input.
0
 
David RobitailleAnalyst ProgrammerCommented:
I confirm you that it dont make much difference. it just make code easier to read
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now