--------------------------------------------------------------------------------
Limitations in Classic ASP
The listing below was copied from the previous chapter:
Hello W3Schools!
<%Response.Write(now())%>
The code above illustrates a limitation in Classic ASP: The code block has to be placed where you want the output to appear.
With Classic ASP it is impossible to separate executable code from the HTML itself. This makes the page difficult to read, and difficult to maintain.
--------------------------------------------------------------------------------
ASP.NET - Server Controls
ASP.NET has solved the "spaghetti-code" problem described above with server controls.
Server controls are tags that are understood by the server.
There are three kinds of server controls:
HTML Server Controls - Traditional HTML tags
Web Server Controls - New ASP.NET tags
Validation Server Controls - For input validation
--------------------------------------------------------------------------------
ASP.NET - 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
The executable code itself has been moved outside the HTML.
--------------------------------------------------------------------------------
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:
In the following example we declare a Button server control in an .aspx file. Then we create an event handler for the Click event which changes the text on the button:
No comments:
Post a Comment