Understanding the autoeventwireup in the @ page command

Source: Internet
Author: User

In the past, I did not pay attention to the small property of autoeventwireup, but later I had to study it and finally understood it because of its troubles.

If you write an Asp.net page that contains the server script:

<@ Page Language = C # autoeventwireup = "false" inherits = "chapter3.ch21" %>
<HTML>
<Script language = C # runat = Server>
Void page_load (Object sender, eventargs E)
{
Lblmessage. Text = "<a href = 'HTTP: // techmango.com '> thinking in techmango.com </a> ";
}
</SCRIPT>
<Body>
<Form runat = Server>
<Asp: Label id = lblmessage runat = server/>
</Form>
</Body>
</Html>

After running, the results are not displayed. Why ?! Of course, it is because autoeventwireup is set to false.What does autoeventwireup mean?CodeWhat is the impact. I checked msdn.AutoeventwireupIndicates whether the page events are automatically connected to the network. If event auto-connection is enabledTrueOtherwiseFalse.
I searched Google again and found a simple and clear answer:
If the autoeventwireup attribute of the page command is set to true (or if this attribute is missing because it is set to true by default), the page framework automatically calls the page events, namely the page_init and page_load methods. In this case, no explicit handles clause or delegation is required.

WhenAutoeventwireupIf this parameter is set to true, the server-side script in HTML is executed and the result is displayed on the page!

But! Conversely,WhenAutoeventwireupIf it is set to false, it is advantageous. Why? Of course, because we often use post-code technology, ifWhenAutoeventwireupIf it is true, the page will be executed twice ,.. NET environment will execute once to run the server-side scripts contained in HTML, and once again to execute the various functions in the code.

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.