ASP.NET Table Control and Evens

11:01 PM Posted by Isha

In ASP.NET table control is used to produce a a table in a web page and we can add some events to it as shown here. We are going to use some web controls in active server pages dot net.

A table is used to display information in a tabular format. A table consists of rows and columns. The intersection of a row and a column is called a cell. You can add a table to a Web Forms page by using the Table control in asp.net. This control displays information statically by setting the rows and columns at design time. Also, you can program the Table control to display information dynamically at run time.

You can add rows at design time by setting the Rows property, which represents a collection of TableRow objects; a TableRow object represents a row in the table. You can add cells to a table row by setting the Cells property of the TableRow object. The Cells property represents a collection of TableCell objects; a TableCell object represents a cell in a table row.

Thus, to set rows and columns of a table at the design time, you first add the Table control to the form. Then, set the Rows property of the Table control to add TableRow objects. Finally, set the Cells property of the TableRow objects to add TableCells objects.

The steps are given as follows:

1. Display the Properties window of the Table control.

2. Click the ellipsis button for the Rows property of the Table control.

3. In the TableRow Collection Editor dialog box, click Add to create a new row. A new row is created and its properties are displayed in the Properties pane of the dialog box.

4. Verify that the row is selected in the Members list, and then click the ellipsis button for the Cells property to add a cell for the row.

5. In the TableCell Collection Editor dialog box, click Add to create a new cell.

You can also add the rows and columns (cells) to a table at run time programmatically.

To do so, you first need to create the TableRow and TableCell objects:

Dim Table1 as New Table()
Dim TableRowObj As New TableRow()
Dim TableCellObj As New TableCell()
Then, you need to add the TableCell object to the TableRow object:
TableRowObj.Cells.Add(TableCellObj)

Finally, you need to add the TableRow object to the Table control.

Image control

The Image control allows users to display images in a Web Forms page and manage them at design time or at run time. After you add an Image control to a Web Forms page, you need to set the image to be displayed in the control. You can do so by using the ImageUrl property.

Button, LinkButton, and ImageButton controls

The Button control on a Web Forms page is used to perform an event, such as form submit, on the server. You can create three types of server control buttons:

Button: Represents a standard button.

LinkButton: Represents a button that can act as a hyperlink in a page. However, a LinkButton control causes the page to be submitted to the server.

ImageButton: Represents a graphical button to provide a rich button appearance. You can set the ImageUrl property to point to a specific image.

Working with Events in ASP.NET

A Web Forms application provides fast, dynamic, and user-interactive Web Forms pages. When users interact with different Web controls on a page, events are raised. In the traditional client forms or client-based Web applications, the events are raised and handled on the client side. However, in Web Forms applications, the events are raised either on the client or on the server, but are always handled on the server. ASP.NET server controls support only server-side events, while HTML server controls support both server-side and client-side events.

Round trips in active server pages :

Most Web pages require processing on the server. For example, consider an Orders Web page used to receive orders on the Web. When a user enters a value for the quantity of a product to be bought, the page must check on the server to see whether or not the quantity requested is available. This type of dynamic functionality is accomplished by handling server control events.

Whenever a user interaction requires some kind of processing on the server, the Web Forms page is submitted to the server, processed, and then returned to the browser (client).This sequence is called a round trip.

Most of the user interactions with the server controls result in round trips. Because a round trip involves sending the Web Forms page to the server and then displaying the processed form in the browser, the server control events affect the response time in the form.

Therefore the number of events available in Web Forms server controls is limited, usually to Click events. The events that occur quite often, such as the OnMouseOver event, are not supported by server controls. However, some server controls support events that occur when the control's value changes.

By default, only the Click event of the Button, LinkButton, and ImageButton server controls causes the form to be submitted to the server for processing — the form is said to be posted back to the server. The Change events associated with other controls are captured and cached and do not cause the form to be submitted immediately.

When the form is posted back (as a result of a button click), all the pending events are raised and processed. No particular sequence exists for processing these Change events, such as TextChanged and CheckChanged on the server. The Click event is processed only after all the Change events are processed.

You can set the change events of server controls to result in the form post back to the server. To do so, modify the AutoPostBack property to True.

Event handlers in asp.net:

When the events are raised, you need to handle them for processing. The procedures that are executed when an event occurs are called event handlers. An event handler is associated with the corresponding event by using the WithEvents and Handles keywords. The WithEvents keyword is used to declare the control generating an event.

For example, when you declare a control, say Image1 as 'Protected WithEvents Image1 As System.Web.UI.WebControls.Image', the WithEvents keyword specifies that Image1 is an object variable used to respond to events raised by the instance assigned to the variable. The Handles keyword is used to associate the event handler with the event, which is raised by the control.

The control in turn is declared by using the WithEvents keywords.

Event handlers are automatically created when you double-click the control in Design mode of the form. For example, the following code is generated when you double-click a Button control whose ID is RegisterButton. You can then write the code in the event handler to perform the intended task.

Public Sub RegisterButton_Click(ByVal sender As System.Object,

ByVal e As System.EventArgs) Handles RegisterButton.Click

Related posts

asp.net forms building part one two and three

0 comments:

Post a Comment