How to hide UpdatePanel

Source: Internet
Author: User
Some people have read the title of the article. Maybe the first response is: Do you need to write an article to this point? Directly UpdatePanel. Visible = false (as the saying goes: Think about it with your ass, haha ~~), I thought so when implementing this code today. I did not expect an error, and the UpdatePanel was not hidden. Looking back, it is not difficult to explain the cause of Ineffective performance. The reason why we use UpdatePanel is to implement partial refresh. Every refresh uses UpdatePanel as a container. Since it is a container, it cannot be changed, but another way to make UpdatePanel invisible is to make the div generated by UpdatePanel disappear from the DOM. Since the refreshed containers disappear, what is used for refresh is simply a daydream ~.

Client Solution
So I searched for this question on the MSDN Forum. Several posts asked this question, but the answer I saw was basically a piece of javascript. I set the display of the div generated by UpdatePanel to none, this is indeed a feasible solution, but this method will result in inconsistent control states on the server side and the client side (unless you plan to write a JavaScript code yourself to update the server status ), once full postback is performed, the user may see this UpdatePanel again. What's more, this hidden code usually needs to execute some server-side judgment logic, but it may not achieve the expected results on the client side.

Prompt
In ASP. NET, if the control's Visible is false, the entire control will not be rendered, that is, there will be no HTML elements (such as span, div, a, etc ).

Server Solution
The first thing that comes to mind is the UpdatePanel Panel. Since there is no way to refresh yourself, let the parent UpdatePanel refresh the sub-Panel. Technically, this is feasible, but pay attention to it, the div generated by the Panel cannot contain any elements, and the UpdatePanel cannot set the width and height. This is because div is a block by default, but without the width and height, it will not occupy any space, otherwise it will act as a placeholder. Once the Visible of the sub-Panel is changed to false, the code generated by UpdatePanel and its sub-elements is as follows:
<Div id = "UpdatePanel1"> </div>

This is the solution we need!

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.