Border Attribute on Table Webcontrol

U

Unknown

When I create a Table webcontrol programmatically (no static table tag in
the aspx file), it renders in the HTML with a border attribute set to "0".

If I add my own border attribute--MyTable.Attributes.Add("border",
"1")--with a value of "1", the border attribute shows up twice in the HTML
tag in the browser.

How can I suppress the default border attribute of "0" for the Table
webcontrol?

Thanks
Phil
 
U

Unknown

Pretty basic stuff here. Below you will find the code for the aspx file,
the c# code behind file, and the html markup taken from "view source" in the
browser window. Please note that the border attribute is repeated twice in
HTML file for the table.

The operating environment is:
-- VS.Net: 7.0
-- .Net Framework: 1.0
-- IE: 6.0

Thanks,
Phil

----------------
ASPX file:
----------------

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="TableBorder.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">

<form id="Form1" method="post" runat="server">

</form>

</body>
</HTML>

----------------
Code behind:
----------------

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace TableBorder
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
Table tbl = new Table();

tbl.Attributes["border"] = "1";

Control FormControl = FindControl("Form1");

FormControl.Controls.Add(tbl);
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}

----------------
HTML file
----------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">

<form name="Form1" method="post" action="WebForm1.aspx" id="Form1">
<input type="hidden" name="__VIEWSTATE"
value="dDwtMTI3OTMzNDM4NDs7Po6uD/OBrot+Jddth/EAV3CvXJRf" />


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

</table></form>

</body>
</HTML>
 
T

Tom Kiefer

Have you tried, instead of
tbl.Attributes["border"] = "1";

simply

tbl.Border = 1;

http://msdn.microsoft.com/library/e...ebuihtmlcontrolshtmltableclassbordertopic.asp

- Tom Kiefer
thogek @ earthlink . net


Unknown said:
Pretty basic stuff here. Below you will find the code for the aspx file,
the c# code behind file, and the html markup taken from "view source" in the
browser window. Please note that the border attribute is repeated twice in
HTML file for the table.

The operating environment is:
-- VS.Net: 7.0
-- .Net Framework: 1.0
-- IE: 6.0

Thanks,
Phil

----------------
ASPX file:
----------------

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="TableBorder.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">

<form id="Form1" method="post" runat="server">

</form>

</body>
</HTML>

----------------
Code behind:
----------------

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace TableBorder
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
Table tbl = new Table();

tbl.Attributes["border"] = "1";

Control FormControl = FindControl("Form1");

FormControl.Controls.Add(tbl);
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}

----------------
HTML file
----------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">

<form name="Form1" method="post" action="WebForm1.aspx" id="Form1">
<input type="hidden" name="__VIEWSTATE"
value="dDwtMTI3OTMzNDM4NDs7Po6uD/OBrot+Jddth/EAV3CvXJRf" />


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

</table></form>

</body>
</HTML>
 
U

Unknown

Using "tbl.Border = 1" seems to create an inline CSS style; We want to use
only the border attribute of the table element in this particular case for a
number of unrelated reasons.

Phil



Tom Kiefer said:
Have you tried, instead of
tbl.Attributes["border"] = "1";

simply

tbl.Border = 1;

http://msdn.microsoft.com/library/e...ebuihtmlcontrolshtmltableclassbordertopic.asp

- Tom Kiefer
thogek @ earthlink . net


Unknown said:
Pretty basic stuff here. Below you will find the code for the aspx file,
the c# code behind file, and the html markup taken from "view source" in the
browser window. Please note that the border attribute is repeated twice in
HTML file for the table.

The operating environment is:
-- VS.Net: 7.0
-- .Net Framework: 1.0
-- IE: 6.0

Thanks,
Phil

----------------
ASPX file:
----------------

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="TableBorder.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">

<form id="Form1" method="post" runat="server">

</form>

</body>
</HTML>

----------------
Code behind:
----------------

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace TableBorder
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
Table tbl = new Table();

tbl.Attributes["border"] = "1";

Control FormControl = FindControl("Form1");

FormControl.Controls.Add(tbl);
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}

----------------
HTML file
----------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">

<form name="Form1" method="post" action="WebForm1.aspx" id="Form1">
<input type="hidden" name="__VIEWSTATE"
value="dDwtMTI3OTMzNDM4NDs7Po6uD/OBrot+Jddth/EAV3CvXJRf" />


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

</table></form>

</body>
</HTML>
 

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,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top