An important discovery of Asp.net (the event function that controls the execution order of page_load ).

Source: Internet
Author: User

Data cannot be updated during an update function today. I set the breakpoint to trace and found this problem.
First lookCode:

Protected   Void Page_load ( Object Sender, eventargs E)
{
// Before ispostback is added, teacher. Update (txtname. Text); The txtname. Text here will never change,
// Because BIND () is executed first and then btnok_click ();
If ( ! Ispostback)
BIND ();
}
Private   Void BIND ()
{
Txtname. Text =   " Hello " ;
}
Protected   Void Btnok_click ( Object Sender, eventargs E)
{
Teacher. Update (txtname. Text );
}

When I click the update button, the data is always unchanged, and it can be updated simply by changing to teacher. Update ("hi.
It's really strange that when I set a breakpoint for debugging, I found that when I didn't add ispostback to the judgment, I first executed page_load ();
Then, run btnok_click (). After being depressed for a long time, write it out and remind other friends.

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.