Use inheritance to bind data to each CS File

Source: Internet
Author: User
A new project was recently started, and almost every page's page_load event needs to be written

Page_load

1 Protected   Void Page_load ( Object Sender, eventargs E) {
2If(!This. Ispostback)
3BIND ();
4}

So I thought

Pagebase 1 Public   Class Pagebase: system. Web. UI. Page
2 {
3 Protected   Void Page_load ( Object Sender, eventargs E) {
4
5If(!This. Ispostback)
6BIND ();
7}
8
9 Protected   Void Page_error ( Object Sender, eventargs E) {< br> 10 exception ex = server. getlasterror ();
11 // Exception Handling
12 server. clearerror ();
13 }
14
15 Protected   Virtual   Void BIND () {}
16 }
17

Then inherit from the pagebase in each page, delete the page_load (Object sender, eventargs e) automatically generated by Vs, and then rewrite the BIND () method:

BIND () 1 Protected   Override   Void BIND () {
2 Textbox1.text =   " Test Cases " ;
3 Throw   New Exception ( " Case Error! " );
4 }
5

Run it. The page is normal.

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.