|[ LiB ]|
ASP.NET is based on a scripting paradigm that is significantly different from ColdFusion MX. Scripting gives developers tremendous power, but the trade-off is that the code beyond the provided server scripts mostly has to be hand-coded . Many of the objects in the insertion bar are just shortcuts for hand-coding.
The Register Custom Tag object inserts code into the page to lay out and access custom server controls on the page.
Several Macromedia custom tags are inserted with the ASP.NET server behaviors. Inserting them and looking at the resulting code is a good place to start with Custom Tags.
For detailed explanations of ASP.NET tags, see the "ASP.NET Resources" section at the end of this chapter.
The server variables are as follows :
TagPrefix Sets the tag's prefix, which associates it with a namespace.
TagName Sets the tag's name , which associates it with a class in the namespace.
Src Sets the namespace to associate with the TagPrefix .
<%@ Register TagPrefix="MM" Namespace="DreamweaverCtrls" Assembly="DreamweaverCtrls,version=18.104.22.168, publicKeyToken=836f606ede05d46a,culture=neutral" %>
This code is inserted by the DataSet server behavior. It sets a namespace of DreamweaverCtrls that contains the custom controls used by Dreamweaver. Inserting any ASP.NET server object also inserts the @Register tag to the same namespace. The TagPrefix is the first part of the custom tag name.
The Import Namespace tag inserts a reference to a custom namespace or a part of the .NET Framework. ASP.NET allows you to use custom controls and abstracted snippets of code. Importing a namespace explicitly declares the path to any of those controls you are using in the application.
The Import Namespace object inserts the following code:
<%@ Import Namespace="" %>
The Trimmed Form Element inserts the Trim() method into an expression that removes any spaces from the beginning and/or end of the value of the form element you are trimming.
The Trimmed Form Element object inserts the following code:
The Trimmed QueryString element inserts the Trim() method into an expression that removes any spaces from the beginning and/or end of the URL parameter you are trimming.
The Runat Server object simply inserts 'runat="server"' into the code. The Runat Server attribute is necessary in a number of tags. The tag is simply a shortcut for hand-coding.
As soon as you have a DataSet defined in a page, you can bind the data from each field of the table to objects on the page. The notation for this is <%# %> .
Here's an example:
<%# FindDepartment.FieldValue("departmentname", Container) %>
In this code, the departmentname field from the FindDepartment DataSet will be placed on the page.
<ASP:Repeater runat="server" DataSource='<%# FindDepartment.DefaultView %>'> <ItemTemplate> <%# FindDepartment.FieldValue("departmentname", Container) %> </ItemTemplate> </ASP:Repeater>
In this code, the same data is bound to the page, but in this case it is wrapped in a Repeater that loops through the set of data found in the Data Set and prints each record.
Page_Load is an event that is executed every time a page is loaded. Dreamweaver inserts more than just the Page_Load event; it inserts a code block that checks to see whether a page is posting back to itself. If it is, code gets executed. If the page is not posting back, the code does not get executed. Dreamweaver inserts the code block, but you still need to hand-code the functions that get executed.
The Page_Load object is especially useful when you have to process a form that posts back to itself. In this case, you might have a large control like the DataGrid that works with data from the form only if the form is filled out. If the page is called for the first time without the form information being filled out, the code to populate the DataGrid should not be executed.
Dreamweaver inserts the following code:
<script runat="server"> Sub Page_Load(Src As Object, E As EventArgs) If Not IsPostBack Then DataBind(); End If End Sub </script>
|[ LiB ]|