Solved

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

Posted on 2008-10-25
4
1,163 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
getting id from database 5 37
Jquery autocomplete 10 69
Registering DLL 5 43
Code works but it's slow 24 45
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now