Docsity

ASP.NET Web Server Controls vs. HTML Server Controls: Differences and Examples, Summaries of Web Programming and Technologies

Toggle sidebar
bg1
ASP notes
1
ASP notes
HTML Server Controls vs. ASP.NET Web
Server Controls:
HTML Server Controls:
HTML server controls in classic
ASP.NET provide properties and methods that ease the migration from classic ASP
to ASP.NET pages. They closely resemble HTML elements and offer familiar
attributes. However, some differences exist between HTML server control attributes
and HTML element attributes.
Abstracted Model: HTML server controls map closely to HTML elements. They
provide an abstraction over HTML and are designed to mimic HTML elements,
making it simpler for developers transitioning from classic ASP.
Single Control vs. Separate Controls: For example, in HTML, a single <select>
tag can serve both list and dropdown functionalities. In contrast, ASP.NET provides
separate controls for this purpose, such as the ListBox and DropDownList controls.
ASP.NET Web Server Controls:ASP.NET web server controls have an abstracted
model that doesn't directly map to HTML elements. Their attributes and functionalities
may differ from HTML controls.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17

Partial preview of the text

Download ASP.NET Web Server Controls vs. HTML Server Controls: Differences and Examples and more Summaries Web Programming and Technologies in PDF only on Docsity!

ASP notes

HTML Server Controls vs. ASP.NET Web

Server Controls:

HTML Server Controls: HTML server controls in classic ASP.NET provide properties and methods that ease the migration from classic ASP to ASP.NET pages. They closely resemble HTML elements and offer familiar attributes. However, some differences exist between HTML server control attributes and HTML element attributes. Abstracted Model: HTML server controls map closely to HTML elements. They provide an abstraction over HTML and are designed to mimic HTML elements, making it simpler for developers transitioning from classic ASP. Single Control vs. Separate Controls: For example, in HTML, a single tag can serve both list and dropdown functionalities. In contrast, ASP.NET provides separate controls for this purpose, such as the ListBox and DropDownList controls.

ASP.NET Web Server Controls: ASP.NET web server controls have an abstracted model that doesn't directly map to HTML elements. Their attributes and functionalities may differ from HTML controls.

Abstracted Model: ASP.NET web server controls provide an abstraction over HTML and have a model that might not directly correspond to HTML elements. This abstraction allows for more powerful and flexible controls. Separate Controls: Unlike HTML, where a single control can serve multiple purposes, ASP.NET provides separate controls for specific functionalities. For example, ListBox and DropDownList controls serve distinct purposes. Standard Control Categories: ASP.NET standard controls can be categorized into three main types:

  1. Table Control: Controls related to tabular data representation and manipulation.
  2. Form Control: Controls that help in form-related operations and user input.
  3. General Control: General-purpose controls with various functionalities beyond tables and forms. Common Properties: Standard controls in ASP.NET share several common properties:
  4. BackColor: Sets the background color of the control.
  5. BorderColor: Defines the color of the control's border.
  6. BorderStyle: Specifies the style of the control's border.
  7. CssClass: Assigns a CSS class to the control for styling purposes.
  8. Enabled: Determines whether the control is enabled or disabled.
  9. EnableTheming: Specifies whether theming is applied to the control.
  10. ForeColor: Sets the foreground color (text color) of the control.
  11. Height: Defines the height of the control.
  12. Width: Sets the width of the control.
  13. SkinID: Associates a control with a skin from the skin file.
  14. ID: Provides a unique identifier for the control.

This creates a Calendar control named calEventDate for selecting dates.

ASP.NET Table Controls ( ):

ASP.NET provides a web server control, (^) , for the creation of HTML tables. This control is mapped to HTML (^) , (^) (table row), and (^) (table cell) elements. It is often used to build tables dynamically, especially when the content is not known at design time.

Example Table Structure:

  1. CellPadding: Specifies the padding within cells of the table.
  2. CellSpacing: Specifies the spacing between cells of the table.
  3. HorizontalAlign: Specifies the horizontal alignment of the table.
  4. Rows: Represents the collection of rows within the table.

Properties of (Rows):

  1. Cells: Represents the collection of cells within a particular row.

Properties of (Cells):

  1. ColumnSpan: Specifies the number of columns a cell should span.
  2. RowSpan: Specifies the number of rows a cell should span.
  3. Text: Specifies the text content of the cell.
  4. Wrap: Specifies whether the content of cells will be wrapped.

Dynamically Creating a Table in VB.NET:

Dim T1 As New Table() Dim Tr As New TableRow() Dim Tc As New TableCell()

' Add the TableRow to the Table T1.Rows.Add(Tr)

' Add the TableCell to the TableRow Tr.Cells.Add(Tc)

In this example, a new Table^ control ( T1^ ), a TableRow^ ( Tr^ ), and a TableCell^ ( Tc^ ) are created. The TableRow^ is then added to the Table^ , and the TableCell^ is added to the TableRow (^). This is a simple example, and you can dynamically add more rows and cells in a similar manner.

Keep in mind that this is a server-side approach, and you can perform these operations in the code-behind file ( .aspx.vb^ ).

' Create a new Table Dim myTable As New Table() myTable.ID = "myTableId"

' Add the table to the form form1.Controls.Add(myTable)

' Create rows and cells dynamically For i As Integer = 1 To 3 Dim row As New TableRow()

For j As Integer = 1 To 3 Dim cell As New TableCell() cell.Text = $"Row {i}, Cell {j}" row.Cells.Add(cell) Next

' Add the row to the table myTable.Rows.Add(row) Next End Sub End Class

In this example, we create a simple with a border, and during the initial page load, we call the CreateDynamicTable function in the code-behind to dynamically add rows and cells to the table. Adjust the logic inside CreateDynamicTable as per your specific requirements.

ASP.NET Form Controls:

1. Label Control:

Purpose: The Label control in

ASP.NET serves the purpose of displaying static text on a webpage. It is commonly used for presenting non-editable content such as validation messages or informational text.

Usage:

Display static text on the webpage. Text content can be specified either in the markup or programmatically at runtime. Non-editable by users during runtime.

Syntax:

4. LinkButton Control ( ):

Purpose: The LinkButton control resembles an HTML hyperlink but functions like a button. It can execute code on its click event.

Properties:

  1. Text: The text displayed within the link button.
  2. PostBackUrl: Specifies the URL of the page to post to.
  3. CausesValidation: Determines if the page is validated when the button is clicked.

Example:

Partial Class LinkB Inherits System.Web.UI.Page Protected Sub Link_Click (ByVal sender As Object, ByVal e As Sy ' Code to execute on link button click End Sub End Class

5. Button Control:

Purpose: The Button control creates a push button on a web form, which can function as either a submit button or a command button.

Properties:

  1. CausesValidation: Determines whether the page is validated when the button is clicked.
  2. Text: The text displayed on the button.
  3. PostBackUrl: Specifies the URL of the page to post to.
  4. CommandName: Specifies the command associated with the command event.
  5. OnClientClick: The name of the function to be executed when the button is clicked.

Example:

Partial Class Content Inherits System.Web.UI.Page Protected Sub btnA_Command (ByVal sender As Object, ByVal e As ' Code to execute based on the command button clicked End Sub End Class

6. ImageButton Control:

Purpose: The ImageButton control in ASP.NET is used to display a clickable image on a webpage. It allows users to interact with the webpage by clicking on the image. The control supports both click and command events similar to the Button control.

Usage:

Display a clickable image on the webpage. Supports both click and command events for additional functionality.

Properties:

  1. ID: Identifies the control for referencing in code-behind.
  2. ImageUrl: Specifies the URL of the image to be displayed on the button.
  3. CommandName: The name of the command associated with the command event.

Example:

End Sub End Class

8. CheckBox Control:

Purpose: The CheckBox control is a web server control that allows users to switch between yes or no, or true or false options. It is ideal for providing multiple options to the user.

Properties:

  1. AutoPostBack
  2. Checked
  3. Text

Events:

CheckedChanged: Triggered when the checked state of the checkbox changes.

Example:

  1. FileBytes: Returns the number of bytes of the file as an array.
  2. FileContent: Returns the content of the file as a stream.
  3. FileName: Returns the name of the file uploaded.
  4. HasFile: Specifies whether a file is selected or not.

Example:

Type : Defines the data type (Integer, Double, Date). MinimumValue , MaximumValue : Sets the allowed range. Example:

OnServerValidate : Points to the server-side validation function. Example:

ASP.NET Event Handlers:

Page_Load Event Handler:

Purpose: Executed when the page is loaded.

Example:

protected void Page_Load(object sender, EventArgs e) { // Code to be executed when the page loads }

protected void gridView1_RowCommand(object sender, GridViewComma { if (e.CommandName == "Delete") { // Code to handle delete command } }

TextBox_TextChanged Event Handler:

Purpose: Executed when the text in a TextBox control changes.

Example:

application and the underlying database, enabling you to easily retrieve, update, insert, or delete data.

Key Properties:

  1. ConnectionString: Specifies the connection string to the SQL Server database.
  2. SelectCommand: Defines the SQL query or stored procedure to retrieve data.
  3. InsertCommand, UpdateCommand, DeleteCommand: Define SQL queries or stored procedures for corresponding operations.
  4. ProviderName: Specifies the ADO.NET data provider to use (e.g., "System.Data.SqlClient" for SQL Server).

Example:

Suppose you have a table named Employees in your SQL Server database with columns EmployeeID , FirstName , LastName , and Salary. Here's how you can use the SqlDataSource control:

In this example:

ConnectionString is set to a connection string defined in the web.config file. SelectCommand retrieves all columns from the Employees table. DeleteCommand is specified to delete a record based on the^ EmployeeID parameter.

Example with GridView:

You can bind the (^) SqlDataSource to a data-bound control like (^) GridView for displaying data. Here's an example: