Search code examples
asp.net.netgridviewcustom-server-controlsservercontrols

Extending .net control: How to prevent HTML atttribute from rendering


I've written a server control that extends the standard .net Gridview control.

However, by default the standard gridview control adds a border="0" attribute to the html markup that it produces, and I want to prevent this attribute from being rendered by my server control.

I could probably use ScriptManager to add a bit of Javascript that removes the attribute once the page that the control sits on has loaded, but that seems a bit clunky and I was hoping that somebody could tell me how to do it cleanly by, for example, adding this.Attributes.Remove("border"); to the PreRender event of the control or something similar (which didn't work by the way, or I wouldn't have to ask the question)


Solution

  • I am using a devexpress gridview so it might be a bit different, but I noticed the same thing happening, and I added

    grid.Attributes["border"] = "";
    

    to the page load event, and the border no longer rendered in html. A bit of a hack but it worked for me.