In ASP, the output of a single value is often used. For example, <% = request ("comeurl") %>, a value is assigned after the equal sign. In ASP. NET, I used to prefer to put a Label control or Literal control in this position. In fact, ASP. NET also has such a binding process, which can be similar to the following implementation:
When code-behind is used, <% # GoodName %> is written in the page code where necessary, and protected string GoodName is written in the page class; In the Page_Load event, BIND as follows:
Private void Page_Load (object sender, System. EventArgs e)
{
If (! IsPostBack)
{
GoodName = "hello! ";
DataBind ();
}
}
The DataBind () method is the method in the Page class. Of course, the GoodName method is better than the property method.
This method can be used to change the Title of a page according to the data in the page. Because the Title attribute of an Html page is outside the Form, another benefit is that, this variable can be assigned a value at a time, which is used everywhere on the page without having to assign the same value to multiple controls.