通过查看System.Web.UI.HtmlControls命名空间,可以发现,很多HTML对应的标签都可以通过添加runat=”server”属性转化为服务器控件,比如<table>会转化为HtmlTable对象,但像<input >标签可以通过type属性对应不同的服务器对象。当html内的标签没有和上图中的服务器控件匹配时,所有不匹配的html标签都会通过添加runat=”server”转化为HtmlGenericControl服务器控件。下面是对应的服务器控件类与HTML标签之间的对应关系:
HTML Tag | HTML Server Control |
<form> | HtmlForm |
<input type="text"> | HtmlInputText |
<input type="password"> | HtmlInputText |
<input type="radio"> | HtmlInputRadioButton |
<input type="checkbox"> | HtmlInputCheckBox |
<input type="submit"> | HtmlInputButton |
<input type="hidden"> | HtmlInputHidden |
<input type="button"> | HtmlInputButton |
<input type="image"> | HtmlInputImage |
<input type="file"> | HtmlInputFile |
<button> | HtmlButton |
<select> | HtmlSelect |
<textarea> | HtmlTextArea |
<img> | HtmlImage |
<a> | HtmlAnchor |
<table> | HtmlTable |
<tr> | HtmlTableRow |
<td> | HtmlTableCell |
其他标签eg:<div> | HtmlGenericControl |