Ben Ben - 24 days ago 12
ASP.NET (C#) Question

asp:Gridview & asp:Table generated border="0" property in > .NET4.0

I understand this is an issue that has been fixed in .NET 4.0+ however, upgrading our framework is not an option as of yet. SOON, but not yet. For the time being I am using .NET 3.5.

As I've seen in many other posts that this is a very common issue. Nobody really seems to say why it is an issue, which is why it seems like many answers don't seem to grasp the actual problem.

When using asp:Table control or asp:GridView control, the generated mark-up looks as such:

<asp:Table id="table1" border="0" runat="server"></asp:Table>


Gridview is much the same but includes a 'rules' attribute that can be ommitted by setting the Gridlines property to "none". However, while setting gridlines to none takes care of the rules attribute, the border="0" always remains.

Now the problem: in order to Validate this code using W3 validator, the border property MUST be set to border="" OR border="1". This seems like a very simple fix, further investigation proves quite the contrary.

I've tried to change the value to something the validator will accept:

ie:

table1.Attributes.Add("border", "1"); // This generates <asp:Table id="table1" border="0" border="1" runat="server"></asp:Table>

table1.Attributes.Add("border", null); // This generates <asp:Table id="table1" border="0" border="" runat="server"></asp:Table>

table1.Attributes["border"] = "1"; // This generates <asp:Table id="table1" border="0" border="1" runat="server"></asp:Table>

table1.Attributes["border"] = ""; // This generates <asp:Table id="table1" border="0" border="" runat="server"></asp:Table>

table1.Attributes.Remove("border"); // This generates <asp:Table id="table1" border="0" runat="server"></asp:Table>


None of these have reached the desired result. asp:Table always generates border="0" and I can't seem to modify the value.

Does anyone have any other ideas, and again, upgrading the framework is not an option for the time being. We will be upgrading at some point in the relatively near future - but not before this version goes to production.

Many Thanks

Answer

I've looked into this issue for quite a while and nothing I read on the Internet could fix this issue and even the Framework 4.0 recommended ideas weren't working since my application was already targetting the Framework 4.0 and still, couldn't remove that "Border=0" from the GridView control. What I've found out though is that my Web.Config, though was targetting the Framework 4.0 also had controlRenderingCompatibilityVersion set to "3.5" on the Pages tag. By removing this setting, it automatically got rid of the "Border" attribute from the GridView control.

Comments