开发者

ASPX in-line code evaluation when parent container is not visible

开发者 https://www.devze.com 2023-02-26 21:33 出处:网络
given the following in-line aspx c# code, if the parent panel (pnlX) had its visibility property set to false in the page load event, would the in-line code be hit?

given the following in-line aspx c# code, if the parent panel (pnlX) had its visibility property set to false in the page load event, would the in-line code be hit?

<asp:Panel ID="pnlX" runat="server">
    <h1>Value is: <%= objectX.prop %></h1>
</asp:Panel>

The reason i ask is that there is some conditional logic (below) where one path sets the objectX object to something. The other path d开发者_JAVA技巧oes not and at the same time sets plnX.Visibility to false. My problem is that i am still getting null reference exceptions on objectX.

objectX = null;
if (true)
{
    objectX = something..
}
else
{
    pnlX.Visible = false;
}

Ta


Have you tried declaring the Panel with Visible="false" in the .aspx file, and then, in your code, instead of setting Visible to false if you don't need the panel, set it to true if you do? I believe that will get around your problem of the null reference.

0

精彩评论

暂无评论...
验证码 换一张
取 消