ASP control vs HTML control

2020-02-12 07:24发布

I'm new to web programming and I've started with ASP.NET 2.0. I would like to know what the differences are when using an HTML control rather than an ASP control, and I'd like to know too how the attribute runat="server" works.

标签: asp.net
2条回答
太酷不给撩
2楼-- · 2020-02-12 07:39

The biggest deference in my opinion is that ASP.NET controls are executed on the server, with the resultant HTML sent to the client and that ASP .NET Server Controls can detect the target browser's capabilities and render themselves accordingly.

查看更多
Emotional °昔
3楼-- · 2020-02-12 07:42

These are the differences between asp.net controls and html controls

  • HTML server controls :

HTML server controls :are HTML tags understood by the server.

HTML elements in ASP.NET files are, by default, treated as text. To make these elements programmable, add a runat="server" attribute to the HTML element. This attribute indicates that the element should be treated as a server control. The id attribute is added to identify the server control. The id reference can be used to manipulate the server control at run time.

Note: All HTML server controls must be within a < form > tag with the runat="server" attribute. The runat="server" attribute indicates that the form should be processed on the server. It also indicates that the enclosed controls can be accessed by server scripts.

Ex: < input type="text" id="id1" runat="server" /> It will work. HtmlTextControl class

< input type="button" id="id2" runat="sever" /> It will not work. For html button control there is no compatiable version of control class.

corrected one is

< input type="submit" id="id2" runat="server" />

htmlButton class

< input type="reset" id="id2" runat="sever" /> This one will not work.

  • ASP.NET - Web Server Controls

Web server controls are special ASP.NET tags understood by the server.

Like HTML server controls, Web server controls are also created on the server and they require a runat="server" attribute to work. However, Web server controls do not necessarily map to any existing HTML elements and they may represent more complex elements.

The syntax for creating a Web server control is:

< asp:textbox id="Textbox1" runat="server" />

These are also case insensitive. Here the important thing is to compulsory write runat="server". For HTML controls this is optional.

all HTML < input type="text" /> control's attributes are also available for these asp tagged server controls. Some special attributes are also there which we will discuss on Ajax for special attributes.

查看更多
登录 后发表回答