Ricardo Appleton
Ricardo Appleton

Reputation: 679

Setting aspx table's visibility to true fails

I'm puzzled here. I have a webform with 3 tables in it. I want to show/hide them according to certain conditions. It all works fine except in one situation.

this is what I have:

<asp:UpdatePanel ID="upGeneral" runat="server" >
    <ContentTemplate>

        <table id="tab1" runat="server" visible="true" width="100%">
           ...
        </table>
        <table id="tab2" runat="server" visible="false" width="100%">
           ...
        </table>
        <table id="tab3" runat="server" visible="false" width="100%">
           ...
        </table>
    </ContentTemplate>
</asp:UpdatePanel>

then, I have a few buttons added to the page, and depending on which one is pressed, I'll change the table's visibility. My problem is that, under certain conditions, I'm changing tab3's visibility to true, and tab1 and tab2's to false, and while tab1 will have it's visibility set to false, tab3 will not have it's visibility set to true... sigh!

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        ...
        if (!editMode)
        {
            tab1.Visible = false;
            tab2.Visible = false;
            tab3.Visible = true;
        }
     }
}

in debug mode, as I go through these instructions, tab3.visibile = true will not change tab3's property! Has this happened to you before? How did you solve it?

Thanks a lot!

Upvotes: 1

Views: 4648

Answers (2)

Crab Bucket
Crab Bucket

Reputation: 6277

The problem could lie with the update panel.

If you are trying to update content from outside of the update panel then you will need to specify the control that will update the panel in the post back element of the panel

<asp:PostBackTrigger ControlID="Button1" EventName="Click">

Without specifying the trigger then the update panel won't update the properties within it.

Upvotes: 2

Shai
Shai

Reputation: 25595

Well, it's possible that your problem lies here:

 if (!Page.IsPostBack)

This will cause the statement inside the if condition to be ran only once - when the page is firstly loaded.

When a postback is issued (i.e you pressed a button), this statement won't be reached.

Try changing to

if (Page.IsPostBack)

Upvotes: 0

Related Questions