Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html control and asp.net web control

Tags:

asp.net

i would like to know what exactly the difference between Html control

and asp.net web control. why do we need these two types of controls?

i have placed one html input text ,html button and asp.net text box AND ASP.NET BUTTON on my web page

    <input id="Text1"    type="text" />

    <input id="Button2" type="button" value="button" />







    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

    <asp:Button ID="Button1" runat="server" Text="Button" />

when i take view source, both are rendered similarly

    <input id="Text1"    type="text" />

    <input id="Button2" type="button" value="button" />




    <input name="TextBox1" type="text" id="TextBox1" />

    <input type="submit" name="Button1" value="Button" id="Button1" />

what is the advantage of web control over html control.

I got some links in the internet,but not clear what exactly

they are used for.

http://www.extremeexperts.com/Net/FAQ/DiffBetweenServerandHTMLControls.aspx.

Could any one please explain the difference between these two controls.

like image 695
Shikha Avatar asked Feb 24 '10 05:02

Shikha


People also ask

What is different between ASP.NET control and HTML control?

Server control events are handled in the server whereas HTML control events are handled in the page. Server controls can maintain data across requests using view state whereas HTML controls have no such mechanism to store data between requests.

What are HTML controls and web controls?

HTML controls are the native browser elements and they are part of HTML language. These are client side controls which is accessible only in the HTML page, so it will improve the performance of the web page. HTML controls on an ASP.NET Web page are not available to the web server.

What is the difference between ASP and HTML?

ASP stands for Active Server Pages and also have capability to dynamically produce web pages based on a specific request from the client. HTML uses tag to write its code which is interpreted by the web browsers to display the content which includes images and objects to be embedded in the webpage.

What is an ASP.NET control?

An ASP.NET control is a . NET class that executes on the server and renders certain content to the browser. For example, in the first ASP.NET page created at the beginning of this chapter, a Label control was used to display the current date and time.


1 Answers

First, if you drag an Html control from the Toolbox onto your design surface as in your example, the tag created does not include runat="server". That means it is native Html tag and not a .NET control. A native Html tag without the runat="server" has no server-side functionality. Thus, you could not set the value of the your "Text1" input tag in the code-behind.

Second, once you add the runat="server" to your Html input tag, you convert it from a native Html tag into a HtmlControl which derives from System.Web.UI.Control. Now the question could morph into the differences between something that derives from System.Web.UI.Control and System.Web.UI.WebControl. However, to specifically address your question, let's compare a standard input type="text" control to the TextBox control:

  1. TextBox control can be access from the code-behind where an input control cannot (not easily) which also means that you can wireup server-side events for a TextBox control whereas you cannot with a standard Html control.
  2. A TextBox control automatically saves its value using ViewState.
  3. A TextBox control can be skinned using a Theme and .skin file whereas a native Html control cannot.
  4. A TextBox can render as either an input type="text" control or a textarea depending on its TextMode property.
  5. A TextBox control can participate in validation using validators.
  6. Last but not least, the TextBox control can use control adapters to render differently in different browsers if required. See http://msdn.microsoft.com/en-us/magazine/cc163543.aspx.

Now, all that said, if you do not need any of WebControl capabilities, then using an native Html control is substantially leaner. In your example, you simply dragged two empty controls onto your design surface. If that is all you needed then using the .NET control would be overkill. However, as you start adding AutoComplete and server-side events and such, the full content, Javascript and all, of what gets to the Browser is much larger.

like image 194
Thomas Avatar answered Sep 23 '22 16:09

Thomas