Duplicate BORDER attribute in WebControl.Table

G

Guest

I've noticed that the WebControl.Table class always outputs the attribute "border="0"", and I cannot stop it from doing so, no matter what I try. I end up with generated HTML that looks like:

<table border="1" border="0">

For example, create a new server control that inherits from System.Web.UI.Control, and call it CustomTable. Add an event handler for the Load event:

Protected Sub CustomTable_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim t As Table
Dim tr As TableRow
Dim td As TableCell

t = New Table
t.Attributes.Add("border", "1")

tr = New TableRow
td = New TableCell

td.Text = "Hello"
tr.Cells.Add(td)

t.Rows.Add(tr)
Me.Controls.Add(t)

End Sub

Create an aspx page, and add your Register stuff at the top:

<%@ Register TagPrefix="CustomTable" Namespace="CustomTable" Assembly = "CustomTable" %>

Then, add the element in the <body>:

<CustomTable:CustomTable runat="server" id="CustomTable1"/>

When you view the web page, you'll see <table border="1" border="0">...

I tried finding somewhere on the MS site where I could submit this as a bug, so I'm hoping someone at MS reads this. If anyone does, is there a workaround?

Thanks,
Bill
 
G

Guest

Hi Bill,

Since you are using a table server control you will have to set the width of the table by using the table.borderwidth property. Even in this case the "border=0" attribute will be seen in the HTML Source since .Net control adds a style attribute to control the table width.
If u want an old fashioned table you can use the HTMLTable object and set the border width by using the table.border=1 .
 
G

Guest

Thank you, Bharat. You are most generous to reply. I switched out to using the HtmlControls.HtmlTable, and it did not exhibit the problem.

Thanks again,
Bill
 
G

Guest

Thank you, Bharat. You are most generous to reply. I switched out to HtmlControls.HtmlTable, and the duplicate BORDER attribute problem went away.

Thanks again,
Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top