Search code examples
http-redirectspotfire

Spotfire Redirecting to home after link click


Ask: Have a button that when clicked downloads a file from a folder on the server and remains on the current page.

Current state and problem: I have a CustomWizardPromptControlPage that writes a simple button to the HTMLTextWriter. The onclick event for the button fires off a window.open(urlToDocument, '_blank'). By doing the button with the onclick it does actually allow me to download the file, however the parent page redirects to the home page.

Already tried: href - didn't download the file and redirected me to the home page. form submit - didn't do anything.

If anyone can give me some insight as to why Spotfire does this and what I can do to stop it from happening it would be greatly appreciated

--Follow up with working code sample for comments request

namespace ACompanyName.SpotFire.ExportWithFilters
{
    public class ExportWithFiltersWebPromptControl : CustomWizardPromptControl
    {
        public ExportWithFiltersWebPromptControl(ExportWithFiltersFileSettings settings)
        {
            this.AddPage(new ExportWithFiltersPage(settings));
        }

        private class ExportWithFiltersPage : CustomWizardPromptControlPage
        {
            private readonly ExportWithFiltersFileSettings _settings;

            public ExportWithFiltersPage(ExportWithFiltersFileSettings settings) : base("Export with Filters")
            {
                _settings = settings;
            }

            protected override void OnGetContentsCore(HtmlTextWriter writer)
            {
                var domain = "https://dev.AURL.com";
                var filename = _settings.ExportWithFiltersFileInfo.Name;
                var fullFilePath = string.Format("{0}/{1}/{2}", domain, "Exports", filename);
                writer.WriteLine("<a href='{0}' target=\"_blank\">Download Export with Filters</a>", fullFilePath);
            }

            protected override void OnGetScriptsCore(StringBuilder builder)
            {
            }

            protected override void OnLeavePageCore(FormData data)
            {
            }

            protected override bool OnValidatePromptCore(FormData data)
            {
                return true;
            }
        }
    }
}

Solution

  • Turned out that Spotfire didn't like putting <button> into the page. Swapped it out with an hyperlink with a target of blank and it worked like a charm. If a button is still desired, stylized div should do the trick.