Difference between <asp:table> and <table>?
Guys What is a difference between both??
if I set <table runat=server>
I can use it at server side also.
Is there开发者_运维知识库 any differnce between both??
Thanx
<asp:Table>
is a .Net object that has specific properties and capabilities that can be utilized through .Net scripting or code behind logic. <table>
is an Html element that can be accessed through scripting and code behind logic, but it has no native .Net capabilities and can only be output as is.
asp:table
lives in the System.Web.UI.WebControls
namespace - these are components that wrap around the different HTML controls and provide a familiar interface and usage to winforms developers (for a table, it will have a Columns
attribute).
table
lives in the System.Web.UI.HtmlControls
namespace and is a direct analogue to the actual HTML controls and provides an interface more familiar to HTML developers (for a table, it will have a Cols
attribute).
In terms of output, these pretty much behave the same way.
- A
<asp:Table>
is an ASP.NET control - A
<table>
is HTML.
Whenever you create an aspx, you're actually modify an XML document that has the representation of HTML - this can include both server side and client side tags.
Your typical web browser has no idea what a <asp:Table>
is because it only understands HTML. Therefore the server (ASP.NET) converts all server side tags into its HTML representation. Therefore if you use your browser to view the source of a page that includes <asp:Table>
you will only see <table>
tags.
The <asp:table>
represents the declarative syntax for the System.Web.UI.WebControls.Table class which is a WebControl. Being a WebControl, it has a much more powerful programming interface and
provides a more object like interface providing for a high level of control.
The <table>
tag on the other hand when used with the runat="server" attribute represents the
System.Web.UI.HtmlControls.HtmlTable class which is a HtmlControl. Being a HtmlControl, it is very basic and provides much lesser programmatic control over it's properties.
HTML elements in ASP.NET files are treated as text, server controls are treated as objects. To make these HTML elements server side programmable you can add a runat="server"
attribute to the HTML element. The main difference between HTML table and <asp:Table>
is the way they can be nested, created, bound and controlled at runtime as an object rather than a string of text.
More information can be found here.
精彩评论