Article

Beginning ASP.NET Using VB.NET - Chapter 14: ASP.NET Server Controls

Page: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 Next

LinkButton

The LinkButton control is functionally very much the Button control. What distinguishes this control, though, is that when rendered in the client browser, it looks like a traditional hyperlink. The LinkButton object's functionality is dependent upon how the OnClick event handler is implemented. The following is an example of a LinkButton declaration:

<html>            
 <body>            
   <form runat="server">            
     <asp:LinkButton id="WroxLinkButton" runat="server"            
       Text="Visit the Wrox Press Home Page" />            
   </form>            
 </body>            
</html>

In this example, the Text property is set, and the OnClick event is assigned the name of the method handler, OnWroxLinkButtonClick. When displayed in the browser, this particular LinkButton will look like this:

14_26_2.jpg

If we added the following event handler an OnClick event to our link button:

<script language="VB" runat="server">            
 Public Sub OnWroxLinkButtonClick(sender As Object , e            
 As System.EventArgs)            
   Response.Redirect("http://www.wrox.com")            
 End Sub            
</script>

An OnClick event to our link button:

<html>            
 <body>            
   <form runat="server">            
     <asp:LinkButton id="WroxLinkButton" runat="server"            
       Text="Visit the Wrox Press Home Page"            
       OnClick="OnWroxLinkButtonClick" />            
   </form>            
 </body>            
</html>

We end up at the Wrox website! Try it for yourself.

This is a button rather than a straightforward hyperlink, therefore we can use it to perform server-side processing, such as logging entries to a database in order to track our web site's URL usage.

Data Rendering Controls

These controls are extremely feature-rich (they have numerous properties to choose from) and greatly simplify the work of displaying a variety of data, particularly database-related data. The definition of "data" in the context of these controls is very broad. It could include database records, an ArrayList, an XML data source and so on.

Before we look at the controls themselves, we need to get hold of two important concepts:

  • Data Binding. This is the term used to describe the process of associating information in a data store (which could be anything from a database table, to an ArrayList object) with a server control. Data binding is established by setting the server control's DataSource property to reference a particular set of data (with a line similar to DataSource = set of data). All data referenced will come from this data source. Once this link has been established, the set of data is then referenced by the DataSet object.
  • Templates. This is a way to define the various layout elements of a particular control; to describe how the data is displayed in the browser. The DataGrid and DataList have default templates, so you only need to create templates if you want to change the default look. Now let's look at those controls:

awroxtbl28.png

There is a great deal to these controls. Each is very powerful, and, unfortunately, it is beyond the scope of this book to examine them thoroughly (each one deserves an entire chapter at least). Let's take a bit of a closer look however, at how each one functions.

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Sponsored Links