Introduction to the Page_Load method in ASP. NET

Source: Internet
Author: User

ASP. NET Load the corresponding Load event and OnLoad method. For this event, I believe most of my friends will be familiar with it, using. the Page_Load method in the page generated by Net is the method for responding to the Load event. For each request, the Load event is triggered and the Page_Load method is executed. I believe most people know about ASP. net.

The Page_Load method responds to the Load event, which is in the System. web. webControl. the class defined in the Control class is the ancestor of Page and all server controls) and is triggered in the OnLoad method.


Many people may have encountered such a problem. They wrote a PageBase class and then verified the user information in Page_Load. The results showed that Page_Load on the subclass page is always executed no matter whether the verification is successful or not, this may leave some security risks. The user may execute the Page_Load method in the subclass without being verified.

The reason for this problem is very simple, because the Page_Load method is added to the Load event in OnInit, And the OnInit method of the subclass adds the Load event first, and then calls the base. onInit, which causes the Page_Load of the subclass to be added first and then executed first.

There are two ways to solve this problem:

1) Reload the OnLoad method in PageBase, verify the user in OnLoad, and then call base. onLoad, because the Load event is triggered in OnLoad, so that we can ensure that the user is verified before the Load event is triggered.

2) Call base. OnInit in the OnInit method of the subclass to ensure that the parent class executes Page_Load first.

The above describes the Page_Load method in ASP. NET.

  1. XML data displayed on the ASP. NET page
  2. What is iframe asp. NET?
  3. ASP. NET lifecycle display
  4. Solve the Problem of ASP. net ajax script errors
  5. ASP. NET Applications

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.