Duplicate BORDER attribute in WebControl.Table

Discussion in 'ASP .Net' started by Guest, Jul 29, 2004.

  1. Guest

    Guest 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
     
    Guest, Jul 29, 2004
    #1
    1. Advertisements

  2. Guest

    Guest 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 .
     
    Guest, Jul 29, 2004
    #2
    1. Advertisements

  3. Guest

    Guest 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
     
    Guest, Jul 29, 2004
    #3
  4. Guest

    Guest 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
     
    Guest, Jul 29, 2004
    #4
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.