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.
- FYI, there's no such thing as an "ASP control". You no doubt mean a web control.John Saunders– John Saunders2011-10-22 13:36:23 +00:00Commented Oct 22, 2011 at 13:36
- possible duplicate of WebControl vs HtmlControl. Cos and pros using them in web forms applicationKV Prajapati– KV Prajapati2011-10-22 13:40:23 +00:00Commented Oct 22, 2011 at 13:40
3 Answers
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.
2 Comments
runat="server" and declare a text box as <input type="text" /> (without runat="server")?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.
1 Comment
runat="server" and declare a text box as <input type="text" /> (without runat="server")?There are various difference between HTML and Asp controls are
if runat=serveris not present in html control then it will be stateless but asp control is stateful that means the information will be retained even after the postBack.<input type="button" id="id2" />// stateless<input type="button" id="id2" runat="server" />// now it will become statefulSecond difference is that html control does not have there class but asp control have the class