ASP. NET Single-value binding

Source: Internet
Author: User

 

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.

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.