[Post] differences between onprerender render

Source: Internet
Author: User

From: http://hi.baidu.com/trip008/blog/item/d6139ab77b5414f130add1e9.html

Protected override void onprerender (eventargs E)
Protected override void render (htmltextwriter writer)
These two differences. Can you tell me?

========================================================== ================

After the Asp.net page triggers the events of each sub-control, it recursively calls the onprerender of the control and recursively serializes the viewstate of the control into a string, finally, recursively call the render output result of the control (the render of the page control writes the viewstate serialized string to the hidden field of the output html ).

Therefore, even if the content created and changed in the render is written to viewstate, it cannot be restored after the page is sent back, the viewstate refilled after the leaf surface is sent back is still the value of onpreder or the previous time.

Therefore, the onprerender of the control is usually used for the last modification (dynamic generation) of the control, but only for HTML output in the render, without changing the control itself.

In addition, when the control is in the vs designer, It is not displayed on the page driven page. Although the design looks like the results of the Asp.net application processing page. At least, the designer does not call onprerender, but calls the display logic based on the methods described in the designer label. In this way, you can make the control display different results in the designer. For example, the table control does not display all bound data in the designer. Instead, it displays a set of sample data that you have created so that you can design the interface layout in a simple way, at the same time, it also allows connection to the database and so on to avoid execution of time-consuming and potentially failed behaviors that are only required during operation.

Here I think of a common phenomenon. Many people have already written custom controls. However, we only understand the runtime control mechanism. The custom controls written out do not support the vs designer control mechanism. For example, this onprerender is not called during design. Users who are proficient in writing custom controls may only use them in the form of program code. The user-defined controls they write are not easy to use in Rad mode, which is common.

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.