I have an issue with a page on a larger project which I've mapped to a standalone, smaller project to isolate the issue and aid experimentation.
In essence, the page has a button which pops up a modal with an n-choice selection (for simplicity, two in the example). The choice of button determines which of two slightly difference files to download. Clicking the button should also dismiss the modal popup.
I cannot get both to happen! As it stands, I can download, but the modal popup remains. Previously, before I added PostBackTriggers for both *_Click events, the modal popup would hide, but no download would happen. Currently, the order of Response.* calls vs modal popup hide appears not to be significant.
Is there a way of coding this such that both happen? Is AjaxToolkit the right way to go? Can I do something with postbacks? This, as you might have gathered, is not my area of expertise, so all advice and tips would be very gratefully received!
Here's my aspx:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Popup_Test_4._5.WebForm1" %><asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"></asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"><asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server"></asp:ScriptManagerProxy><asp:Button ID="SaveFileDirectly" runat="server" Text="Save (Direct)" ToolTip="Save file directly" OnClick="SaveFileDirectly_Click" Style="width: 100px; margin-left: 5px;" /><asp:Button ID="SaveFileIndirectly" runat="server" Text="Save (Indirect)" ToolTip="Save file indirectly" OnClick="SaveFileIndirectly_Click" Style="width: 100px; margin-left: 5px;" /><asp:Button ID="LanguageControl" runat="server" Style="display: none;" /><ajaxtoolkit:modalpopupextender id="LanguageModalPopup" popupcontrolid="LanguagePanel" targetcontrolid="LanguageControl" backgroundcssclass="modalBackground" runat="server"></ajaxtoolkit:modalpopupextender><asp:Panel ID="LanguagePanel" Style="display: none;" runat="server"><asp:UpdatePanel ID="UpdatePanel1" runat="server"><ContentTemplate><p>Which language?</p><div style="text-align: right; margin-top: 10px;"><asp:Button ID="EnglishButton" Text="English" runat="server" OnClick="EnglishButton_Click" /><asp:Button ID="FrenchButton" Text="French" runat="server" OnClick="FrenchButton_Click" /></div></ContentTemplate><Triggers><asp:PostBackTrigger ControlID="EnglishButton" /><asp:PostBackTrigger ControlID="FrenchButton" /></Triggers></asp:UpdatePanel></asp:Panel></asp:Content>
and C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Popup_Test_4._5
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CommonResponse(bool english = true)
{
this.Response.Clear();
this.Response.Buffer = true;
this.Response.ContentType = "text/xxx";
this.Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", "testdownload.xxx"));
this.Response.Write(english ? "hello" : "bonjour");
this.Response.End();
}
protected void SaveFileDirectly_Click(object sender, EventArgs e)
{
CommonResponse();
}
protected void SaveFileIndirectly_Click(object sender, EventArgs e)
{
LanguagePanel.Style["display"] = "block";
LanguageModalPopup.Show();
}
protected void EnglishButton_Click(object sender, EventArgs e)
{
LanguagePanel.Style["display"] = "none";
LanguageModalPopup.Hide();
CommonResponse();
}
protected void FrenchButton_Click(object sender, EventArgs e)
{
CommonResponse(false);
LanguagePanel.Style["display"] = "none";
LanguageModalPopup.Hide();
}
}
}