Hidden ( visible="false") panel is not displayed, but data binding is performed on the contained elements. Why is this done? And more importantly, how to avoid it?
Here is an example where this is annoying:
<asp:Panel ID="UserPanel" runat="server" visible="<%# SelectedUser != null %>">
<%# SelectedUser.Name %>
</asp:Panel>
If SelectedUser- null, the panel is not displayed, but SelectedUser.Nameis evaluated and generates an error.
I could write <%# SelectedUser != null ? SelectedUser.Name : "" %>, but it adds a mess.
Is there a way to simply and elegantly prevent data binding in the panel when I know it is not needed?
The control Panelis not important here, it can be a Placeholder of a simple HTML element with runat="server".
source
share