create a Filter (a class that inherits from Stream ), assign it to your HttpContext.Response.Filter attribute, and you will overwrite the Write method in it to remove all name tags from the generated html :)
See this page for more information http://msdn.microsoft.com/en-us/library/system.web.httpresponse.filter.aspx
Update
Looking at the source code for the TextBox , it shows that the name was actually added to the Attributes list during rendering, so it should be possible to interfere with the rendering of the TextBox class and prevent this attribute from being added. It should do
public class NoNamesTextBox : TextBox { private class NoNamesHtmlTextWriter : HtmlTextWriter { public NoNamesHtmlTextWriter(TextWriter writer) : base(writer) {} public override void WriteAttribute(string name, string value, bool fEncode) { if (name.Equals("name", StringComparison.OrdinalIgnoreCase)) return; base.WriteAttribute(name, value, fEncode); } } protected override void Render(HtmlTextWriter writer) { var noNamesWriter = new NoNamesHtmlTextWriter(writer); base.Render(noNamesWriter); } }
Update again
How could I forget! You do not even need to subclass your text box. In asp.net, you can determine which type of HtmlTextWriter you want to use for each control, so you can simply configure that each TextBox control should use an instance of your own NoNamesHtmlTextWriter like this
<browsers> <browser refID="Default"> <controlAdapters> <adapter controlType="System.Web.UI.WebControls.TextBox" adapterType="NoNamesTextBoxAdapter" /> </controlAdapters> </browser> </browsers> public class NoNamesTextBoxAdapter : ControlAdapter { private class NoNamesHtmlTextWriter : HtmlTextWriter { public NoNamesHtmlTextWriter(TextWriter writer) : base(writer) { } public override void WriteAttribute(string name, string value, bool fEncode) { if (name.Equals("name", StringComparison.OrdinalIgnoreCase)) return; base.WriteAttribute(name, value, fEncode); } } protected override void Render(HtmlTextWriter writer) { var noNamesRender = new HtmlTextWriter(writer); base.Render(noNamesRender); } }
Pauli Østerø Dec 12 '10 at 10:36
source share