Introduce DataBase,Asp.net,JavaScript,Xml,Html,Css,Sql,Php,ASP.NET Controls,AJAX,Tools,HTML,CSS,JavaScript,Open Source Project,WPF,.Net Framework,Linq
Top Recommended Hosting

Asp.net Control: Understanding HTML Controls

by the3factory 2/27/2008 11:02:00 PM

 

You declare HTML controls in a different way than you declare standard ASP.NET controls. The ASP.NET Framework enables you to take any HTML tag (real or imaginary) and add a runat="server" attribute to the tag. The runat="server" attribute converts the HTML tag into a server-side ASP.NET control.

For example, the page in Listing 1 contains a <span> tag, which has been converted into an ASP.NET control.
 
Listing 1. HtmlControls.aspx
<%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Sub Page_Load() spanNow.InnerText = DateTime.Now.ToString("T") End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>HTML Controls</title> </head> <body> <form id="form1" runat="server"> <div> At the tone, the time will be: <span id="spanNow" runat="server" /> </div> </form> </body> </html>

Notice that the <span> tag in Listing 1 looks just like a normal HTML <span> tag except for the addition of the runat="server" attribute.

Because the <span> tag in Listing 1 is a server-side HTML control, you can program against it. In Listing 1, the current date and time are assigned to the <span> tag in the Page_Load() method.

The HTML controls are included in the ASP.NET Framework to make it easier to convert existing HTML pages to use the ASP.NET Framework. I rarely use the HTML controls because, in general, the standard ASP.NET controls provide all the same functionality and more.

Related posts

Sign up for PayPal and start accepting credit card payments instantly.


Powered by BlogEngine.NET 1.2.0.0