Solved

How do I get ASP.NET to stop generating "name" attributes on input tags

Posted on 2008-10-25
4
1,165 Views
Last Modified: 2010-04-21
I have noticed that ASP.NET generates identical name and id attributes on <input> tags generated from <asp:TextBox> controls. However a <span> tag generated from an <asp:Label> control only has the id attribute generated.
It would appear the "name" attribute is useless in this case, as it has the same value as the id for all elements, and the name tag is deprecated.

I would like to stop asp.net from generating Name attributes - I would save 100kb of bandwidth in my HTTPResponse.
0
Comment
Question by:colonel720
  • 2
4 Comments
 
LVL 16

Expert Comment

by:Gyanendra Singh
ID: 22806371
as per my knowledge you cant ... do one thing give some name attribute to yr text box control ...
0
 
LVL 1

Author Comment

by:colonel720
ID: 22806393
I tried:

txt1.Attributes["name"] = string.empty;
this simply added a second name attribute.

and

txt1.Attributes.Remove("name")
no effect

I since read that asp.net uses the "name" property for postbacks and callbacks in client side code.
that is infuriating, seeing as name is not even recognized as valid xhtml 1.1 strict.
So i guess i'm stuck with an extra 100kb of markup, or another 2 seconds or so for the user to wait on postback.
0
 
LVL 15

Accepted Solution

by:
NazoUK earned 250 total points
ID: 22806593
As you say asp.net needs the name attribute to do some of its work, so you can't remove it.
Name IS a valid attribute on input controls and will pass the W3C validation service for valid XHTML 1.1 strict.
If you add the element <xhtmlConformance mode="Strict"/> to the web.config under system.web asp.net won't generate name elements on tags that don't allow it such as <form>.

If losing the name element will save 100kb on a single page (a 100kb page by itself is pretty huge) it sounds like you have far more serious design issues than whether the name element gets added or not.
0
 
LVL 1

Author Closing Comment

by:colonel720
ID: 31510051
Yes, the page is 400kb large. It was designed by someone who didnt know what they were doing, and it'a my job to fix it lol.
It was a grid with 15 textboxes per row, creating 225 textboxes for a grid of 15 rows. The solution i'm looking at now is replacing them all with labels and then using an edittemplate, and maybe sticking the grid in an iframe.

Thanks anyway
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

823 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question