Entanglement between ViewState, UpdatePanel and control Onpre

Source: Internet
Author: User

ViewState and Ajax UpdatePanel together, in some cases, seemingly will cause a full page back, people feel that UpdatePanel failure.

This is found when solving another problem.

The problem is this:

Added a Onpre event to a panel on the page that was placed in the UpdatePanel. Perhaps also related to Tabcontainer, in fact, is this: UpdatePanel put Tabcontainer,tabcontainer in every tab in the Panel.

Only when using ViewState to determine whether to let this panel display (with panel.visible) is normal, each operation will trigger the Onpre event. In other ways, this event is triggered only when the page is loaded for the first time, or when the whole page is postback.

In fact, I noticed that when using ViewState, any action would cause an entire page postback, which is not what we expected. We've added UpdatePanel. Fortunately, although this problem arises, the Onpre event is normal.

However, when not viewstate, UpdatePanel is normal, not full page postback, but Onpre event is not normal.

Focus: why.

The answer is: because in UpdatePanel, if you want to make a control visible false (using the Onpre event), it will never appear again.

The first time the control's visible is false, it will no longer appear (no more onpre will be triggered unless the entire page is sent back). If the visible of this control is true for the first time, the onpre is triggered normally, but if the next time visible is set to false, it will no longer be displayed and its Onpre event will not be triggered.

One way to solve this problem is to:

Avoid using visible for controls located in UpdatePanel and use "display:none;" instead.

Like this:

PANEL.ATTRIBES.ADD ("Style", "display:none;");

If you want to show it, that's it:

Panel.Attribes.Remove ("Style");

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.