5). Pagelet control
The easiest way to do the control is to use the Pagelet control, which is suffixed with. aspc and included in the WebForm using the Register command:
<% @ Register TagPrefix = "Acme" TagName = "Message" Src = "pagelet1.aspc" %>
TagPrefix is the namespace definition of Pagelet, and TagName is the name given to Pagelet. The Src attribute is a virtual directory.
Use of Pagelet:
<Acme: Message runat = "Server"/>
. The Pagelet method is exposed to define attributes like a class, for example:
<Script language = "c #" runat = "server">
Public String Address {
Get {
Return TxtAddress. Value;
}
Set {
TxtAddress. Value = value;
}
}
</Script>
<Input id = "TxtAddress" runat = "server">
. Encapsulate events
Omitted
We can see that Pagelet can replace include files.
. Program to create a Pagelet object
You can use a program to generate an instance of the Pagelet control, for example:
Control cl = LoadControl ("pagelet2.aspc ");
(Pagelet2_aspc) cl). Category = "business ";
Page. Controls. Add (cl );
Note that because the LoadControl function returns a System. Web. UI. Control object, you need to create a shape. Pagelet
The type is file name, and the dot is replaced by an underscore.
6). Data help controls
In asp +, you can not only set the database, but also a simple set of attributes and even the results of method calls, such:
CustomerID: <% # custID %>
<Asp: ListBox id = "List1" datasource = '<% # myArray %> 'runat = "server">
<% # (Customer. FirstName + Customer. LastName) %>
<% # GetBalance (CustID) %>
It looks like <% = %> in asp, but ASP is replaced by Response. Write, while ASP + is in DataBind ()
Method call. Both the data help control and the Page object have the DataBind () method.
Note that asp + is strongly typed, so:
<% # Count. ToString () %>.
. DataBinder. Eval ()
A static method, supported by ASP +, allows the following helper expressions for data, and can also be converted to strings.
Template. If Eval is not used, it is like:
<% # String. Format ("{0: c}", (DataRowView) Container. DataItem) ["SomeInteger"]) %>
You can use Eval:
<% # DataBinder. Eval (Container. DataItem, "someinteger", "{0: c}") %>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service