Html management and asp.net web management

I would like to know what exactly is the difference between Html control

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

I posted 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 the viewer, both are displayed 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 on the Internet, but did not understand what exactly

they are used to.

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

Can someone explain the difference between the two controls.

+6
source share
4 answers

First, if you drag an Html control from a toolbar onto your design surface, as in your example, the created tag does not include runat = "server". This means that it is a native Html tag, not a .NET control. A native Html tag without runat = "server" does not have server-side functionality. Thus, you cannot set the value of the input tag "Text1" in the code.

Secondly, as soon as you add runat = "server" to your Html input tag, you convert it from your own Html tag to HtmlControl, which comes from System.Web.UI.Control. Now the question may turn into the differences between what comes from System.Web.UI.Control and System.Web.UI.WebControl. However, to specifically address your question, compare the standard input = text element with the TextBox control:

  • The TextBox control can be accessed from code where the input control cannot (not easily), which also means that you can connect to server events for the TextBox control, while you cannot use the standard Html control.
  • The TextBox control automatically saves its value using the ViewState.
  • A TextBox control can be bypassed with a Theme and .skin file, while a native Html control cannot.
  • A TextBox may appear as an input element = "text" or a text field, depending on its TextMode property.
  • The TextBox control can participate in validation using validators.
  • Last but not least, the TextBox control can use control adapters to render differently in different browsers, if necessary. See http://msdn.microsoft.com/en-us/magazine/cc163543.aspx .

Now, all that has been said, if you do not need any features of WebControl, then using your own Html control is significantly more compact. In your example, you simply dragged two empty controls onto your design surface. If that's all you need, then using a .NET control will be redundant. However, when you start adding AutoComplete events and server events, etc., Full content, Javascript and everything else that gets into the browser is much more.

+5
source share

In short, HTML controls do not retain their state during Postbacks. ASP.Net management, on the other hand, provides you with the luxury of maintaining your automatic state with multiple relays. Unlike using an ASP.Net control instead of an HTML element:

<input type="hidden" name="__VIEWSTATE" value="dDwtNTI0ODU5MDE1Ozs+.................." />

This hidden field is automatically generated by ASP.Net and contains everything that you control in the value attribute.

+1
source share

Server controls have the runat = "server" attribute, which allows you to provide server logic for these controls in code. You can also add this attribute to existing HTML controls to get the same functionality.

0
source share

HTML controls are simple controls that directly correspond to HTML elements.

ASP.NET web controls abstract out HTML elements and usually provide more control over the style (although some of them would call it bad).

0
source share

All Articles