Sayfalar

5 Şubat 2011 Cumartesi

ASP.NET Is Object-Oriented


ASP provides a relatively feeble object model. It provides a small set of objects; these objects are really
just a thin layer over the raw details of HTTP and HTML. On the other hand, ASP.NET is truly objectoriented.
Not only does your code have full access to all objects in the .NET Framework, but you can also
exploit all the conventions of an OOP (object-oriented programming) environment. For example, you
can create reusable classes, standardize code with interfaces, extend existing classes with inheritance,
and bundle useful functionality in a distributable, compiled component.
One of the best examples of object-oriented thinking in ASP.NET is found in server-based controls.
Server-based controls are the epitome of encapsulation. Developers can manipulate control objects
programmatically using code to customize their appearance, provide data to display, and even react to
events. The low-level HTML markup that these controls render is hidden away behind the scenes.
Instead of forcing the developer to write raw HTML manually, the control objects render themselves to
HTML just before the web server sends the page to the client. In this way, ASP.NET offers server controls
as a way to abstract the low-level details of HTML and HTTP programming.

Here’s a quick example with a standard HTML text box that you can define in an ASP.NET web page:
<input type="text" id="myText" runat="server" />
With the addition of the runat="server" attribute, this static piece of HTML becomes a fully
functional server-side control that you can manipulate in C# code. You can now work with events that it
generates, set attributes, and bind it to a data source.
For example, you can set the text of this box when the page first loads using the following C# code:
void Page_Load(object sender, EventArgs e)
{
myText.Value = "Hello World!";
}
Technically, this code sets the Value property of an HtmlInputText object. The end result is that a
string of text appears in a text box on the HTML page that’s rendered and sent to the client.

Hiç yorum yok:

Yorum Gönder

Bing'ı Seviyoruz. :)
Google'ı Seviyoruz. :)