Asp.net - Can't Change Visibility of Panel After Downloading File

I am displaying a panel that containg a button. When the user clicks the button, it does some processing and then downloads a file for the user. The code for that is shown here:

    private void OpenForm(string content, string formName)
    {
        Byte[] bytes = System.Text.Encoding.Default.GetBytes(content);

        this.Response.AppendHeader("Content-Type", "application/msword");
        this.Response.AppendHeader("Content-Length", bytes.Length.ToString());
        this.Response.AppendHeader("Content-disposition", "attachment; filename=" + formName);
        this.Response.BinaryWrite(bytes);

        ReturnToMemberScreen();

        this.Response.Flush();
        this.Context.ApplicationInstance.CompleteRequest();
    }

In the function ReturnToMemberScreen, I am changing the visibility of some panels. Here is the function:

    private void ReturnToMemberScreen()
    {
        this.panelMappings.Visible = false;
        this.MemberEditPNL.Visible = true;
    }

I can download the file perfectly fine, my issue is that the visibility of my panels don't change. Does it have something to do with writing to the Response like I am?

Answers


Do not use Visible = false as that causes the element to not be rendered. Try:

// To hide:
 Panel1.Style.Add("display", "none");
// To show:
 Panel1.Style.Add("display", "block");

Do you set the visibility of the panels in the Page_Load event? If so, and if you're not handling postbacks within the event, then the visibility settings might be overriding the settings in ReturnToMemberScreen.


Looking closer, I think I cannot make any changes to the page because I am changing the Content-Type of the response from "text/html" to application/msword when I do this:

this.Response.AppendHeader("Content-Type", "application/msword");

As I result, I am making all my changes with CSS and Javascript instead. By default, I set my panels to either show or hide using css:

.hide     
{         
    display:none;     
}

.show
{
    display:block;
}

Then I set the OnClientClick of the button to the following Javascript function to change the display:

function visible() 
{
    document.getElementById('<%=panelForms.ClientID %>').style.display = 'none';
    document.getElementById('<%=MemberEditPNL.ClientID %>').style.display = 'block';
}

Need Your Help

jQuery UI MultiSelect Widget search filter not receiving focus when in a jQuery dialog,

jquery jquery-ui-dialog

I'm having trouble with a jQuery UI MultiSelect widget search filter not receiving focus when in a jQuery dialog. The issue I'm experiencing can be reproduced by viewing the following HTML page in a