7

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.

2

3 Answers 3

7

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Can you please which one of those to use and why ? I read in a book that Microsoft tried to bring its desktop programming to the web , and this is why we have those server control that produces HTML on behalf of the of programmer , but now every programmer should take control over it's html, css and javascript . which we cannot do when using those controls with <asp:> prefix .
so what happens if I declare a form element with runat="server" and declare a text box as <input type="text" /> (without runat="server")?
0

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

so what happens if I declare a form element with runat="server" and declare a text box as <input type="text" /> (without runat="server")?
0

There are various difference between HTML and Asp controls are

  1. if runat=server is 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 stateful

  2. Second difference is that html control does not have there class but asp control have the class

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.