Odd visibility behavior of asp:buttons

Hi there,
I’m seeing some behavior I can’t explain and which I can fix but I’d prefer to understand what’s happening before circumventing it altogether.

Basically I have a form. You hit submit, it calls if Page.IsValid, and if there is a value not in an acceptable range, the original submit button hides (it’s inside a div that I turned into an htmlgenericcontrol so I could hide the whole div instead of each button inside, there is another button) and along with the out of range warning provide by my custom validator, you get new buttons asking you if you want to submit even though this value is OOR, or do you want to cancel that, and keep editing? (Note that these special OOR buttons are hidden on first page load by setting their enclosing div’s visible to false.) So these buttons are now visible because I have set the enclosing divs visibility to true. There are actually 2 pairs of save/cancel, because you can save your work or you can submit your work as complete, which triggers different validation and DB interaction.

You hit cancel to keep editing work, and the cancel method hides the special buttons’ div, and sets the original buttons’ enclosing div’s visible property to true.

You hit submit again despite still having an OOR value, and it triggers the same loop.

BUT here is the rub, the second time, the special buttons never show up.

I step through the code and discover that:

  1. on first page load, the visible property of the special buttons in the div are true, as well as the div itself. Then after the line sets that div’s visible to false, I saw the buttons were also visible=false.
  2. hit submit, the validation calls the toggleOOR, the enclosing div’s visible is set to true, at which point I saw that all of the special buttons were also all visible = true. My code tests that you are in submit mode, and sets the appropriate pair to visible = false.
  3. you hit cancel, the cancel function sets the specialOOR div visible=false, I find every special button’s visible property is false
  4. hit submit again, the validation calls the toggleOOR, the enclosing div’s visible property was found by me to be false at this point, then the code sets it to true, I find its property correctly shows true but unlike step 2, this time, each button’s visible property is still false. What gives?

So this is my confusion. Why does it appear that in my first use of the page, the buttons inherit the visibility of the enclosing div…yet not the second?

Now rather than use enclsong divs I can of course just set the buttons’ visibility directly, I was just trying to save some code.

But I’d still like to understand behavior which seems conflicting to me.

If you read all this, thanks.


This is a bit confusing to follow and debug. Can you maybe post some code for us to review, so that we can try and help find where the problem is coming in.

on (!IsPostBack) this line is called: divOORButtons.Visible = false;

when you click submit:

protected void btnSubmit_Click(object sender, EventArgs e)
            if (Page.IsValid)

in my debugging the page is never valid because of the out of range values, so in the validation this is called

if (nonOOROK)

and in the toggle

protected void ToggleOORButtons(bool submit)
            //turn on oor mode
            SessionManager.Instance.OorMode = true;

            //hide regular buttons
            divRegularButtons.Visible = false;
            //show oor buttons
            [B]divOORButtons.Visible[/B] = true;

            if (submit)
                [B]btnYesSave.Visible[/B] = false;
                [B]btnNoSave.Visible[/B] = false;
                [B]btnYesSubmit.Visible[/B] = false;
                [B]btnNoSubmit.Visible[/B] = false;


the bolded bits are what I’ve hovered over in my stepping through the code while debugging, and noting that in the first time it’s called (the first time you submit the page), divOORButtons.Visible is false when I check it as are the buttons, but when the line divOORButtons.Visible = true is executed, and I hover over the buttons before those lines are called, their visible properties are all now true.

Now, on the page, these buttons (btnNoSubmit, btnYesSubmit) are now showing, and the original submit button is hidden (divRegularButtons.Visible = false; in the toggle method above).

When you click btnNoSubmit, it calls this

protected void CancelOOR(object sender, EventArgs e)
            divOORButtons.Visible = false;
            divRegularButtons.Visible = true;

Appropriately the original Submit/Can pair that is in the divRegularButtons now appear and the ones in divOORButtons are no longer seen.

Now if I do what I just did, that is hit the submit, which triggers the validation, which triggers the toggle method, and I step through the toggle method, this second time, the divOORButtons visible property is again false when I enter the method, switches to true after the divOORButtons.Visible = true line executes - but this time, when I check the buttons inside divOORButtons, the ones from the bolded bit above in the toggle code, they do NOT flip to true before those bolded lines execute.

So basically what I’m confused about is why the these controls Visible properties seem to behave differently when I step through the exact same code the second time around? If changing divOORButtons.Visible to true causes the contained buttons to also flip to true in the first iteration, shouldn’t they behave the same way when I iterate through the second time?