Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

So I have having a weird situation here.

I have an ASP file that outputs a simple table element. <table> in the file mark up.

However when it renders, it is generating <table cellpadding="0" cellspacing="0"> on the final mark up.

I would like to remove cellpadding and cellspacing due to it being an invalid HTML5. I am getting errors when using the HTML5 validator.

Can anyone point me to the right direction in how to remove them?

I have tried using jquery to removeAttr('cellpadding'), in html console, it has removed the attribute, however in the mark up it is still there so HTML5 validator is still showing errors.

Any help would be appreciated. Thanks

share|improve this question
"I have tried using jquery to removeAttr('cellpadding')" — That modifies the DOM, not the HTML, and won't be run by the validator anyway. – Quentin 20 hours ago
If you have <table> in the source file but <table with stuff> gets delivered to the browser, then you need to find whatever is changing it and stop it (and that will be between the source file and it coming out of the server) – Quentin 20 hours ago
@Quentin Usually in WebControls with stuff (i.e. attributes) are rendered based on what is the the Controls (parent of WebControl) Attribute collection (which is a KeyNameValuePair or similar struture). You can modify this by extending the Table class, hooking its prerender event and modifying the Attribute collection – Paul Sullivan 20 hours ago

1 Answer

ASP.NET controls are notorious for spewing out this kind of stuff.

You can either:

  • Learn how the ASP Table works by analysing its code and finding a way to drop the rendering of those attributes (from memory you can cast it back to a WebControl or Control and then you can modify its Attributes[collection] (advanced but easy once you know how)

  • Use ControlAdapter suite cssfriendly (the 'out of the box' solution for newbies) [UPDATE] Looking at cssfriendly it doesn't look like they have implemented a control adapter for Table so you can't use this (other than to examine how they did it and roll your own for Table

  • Write a control adapter (more advanced than just using cssfriendly but hacky imho)

  • Write your own Databound/TemplatedDatabound WebControl (fun but more advanced)
  • Just write raw html with for loops etc (for when you have given up on all of the above)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.