Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I click create button, a file needs to downloaded as XML . This functioanlity Works Correctly in IE. In chrome, Create button does not do any action. There is no postback that's happening in Chrome.

The code is written in a way where during prerender the file gets downloaded.

What I have tried:

ASPX Code
<pre>                        <div style="margin: 6px;"><ent:ERadioButtonGroup id="SaveAsFileRadioButton" runat="server" GroupName="FileTarget">
                        </ent:ERadioButtonGroup><label for="SaveAsFileRadioButton"> Download network template as a file</label></div>
                        <a id="DownloadStubLink" runat="server" target="_blank" style="display:none;"></a>
                        <div style="margin: 6px 6px 0 6px;"><ent:ERadioButtonGroup id="SaveInDatabaseRadioButton" runat="server" GroupName="FileTarget">
                        </ent:ERadioButtonGroup><label for="SaveInDatabaseRadioButton"> Store network template in database</label></div>
                        <table class="EditProfile FixedTable" style="margin-left: 15px">
                            <colgroup>
                                <col class="Column1" />
                                <col class="Column2" />
                            </colgroup>
                            <tr>
                                <td>Network template name:</td>
                                <td>
                                    <ent:ETextBox id="NameTextBox" runat="server" cssclass="InputField" maxlength="255"></ent:ETextBox>
                                    <ent:ERequiredValidator id="RequiredNameValidator" runat="server" 
                                        errormessage="Please supply name for Network template" 
                                        controltovalidate="NameTextBox"
                                        evaluationfunction="ValidateNameTextBox"></ent:ERequiredValidator>
                                </td>
                            </tr>
                            <tr>
                                <td>Network template description:</td>
                                <td><ent:ETextBox id="DescriptionTextBox" runat="server" textmode="MultiLine" maxlength="255" cssclass="InputField TextBox" width="239px"></ent:ETextBox></td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
            <iframe title = "Download Frame" src="../../Common/Images/empty.gif" id="DownloadFrame" style="display:none;"></iframe>
            <script type="text/javascript">
                var saveAsFileCtrls = null;
                var storeToDBCtrls = null;

                function InitCtrls()
                {
                    if(storeToDBCtrls == null)
                    {
                        saveAsFileCtrls = new Array();
                        storeToDBCtrls = new Array(document._all('NameTextBox'),
                                                    document._all('DescriptionTextBox'));
                    }
                }
                function IsPageValid()
                {
                    return EValidatorValidate('RequiredNameValidator');
                }
                function setSaveInDatabaseChecked()
                {
                    document.getElementById('SaveInDatabaseRadioButton').checked = true;
                }
                function RefreshCtrlStatus()
                {
                    InitCtrls();
                    IsPageValid();
                    document.getElementById("NameTextBox").onfocus = setSaveInDatabaseChecked;
                    document.getElementById("NameTextBox").onmousedown = setSaveInDatabaseChecked
                    if(document.getElementById('SaveInDatabaseRadioButton').checked)
                        document.getElementById("NameTextBox").focus();
                }

                function SaveButtonClicked()
                {
                    
                    debugger;
                    if(!IsPageValid())
                        return;

                    if(document._all('SaveAsFileRadioButton').checked)
                    {
                        event.returnValue = false;
                        var downloadFrame = document.frames['DownloadFrame'];
                        downloadFrame.location = document._all('DownloadStubLink').href;
                        // To handle the moment the "File Download dialog" has been closed
                        window.document.body.onfocus = new Function('OnActivate();');
                    }
                }
                
                function OnActivate()
                {
                    // The dialog has been closed - go to the previos page
                    document._all('CancelButton').click();
                }


Code Behind

private void CreateButton_Click(object sender, EventArgs e)
        {
            //Start creation process
            pageData.SaveTemplateToDatabase(NameTextBox.Text, DescriptionTextBox.Text);
            NameTextBox.Text = DescriptionTextBox.Text = String.Empty;
            AxRedirect.Return();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void NetworkCopyPage_PreRender(object sender, EventArgs e)
        {
            if(pageParams.ProduceFile)
            {
                Response.Clear();
				Response.ClearHeaders();
				Response.Cache.SetCacheability(HttpCacheability.Public);
                Response.ContentType = "application/octet-stream";
                Response.AddHeader("Content-Disposition", "attachment; filename=NetworkTemplate.xml");
                Response.Write(pageData.XmlText);
                Response.End();
            }
            else
            {
                DisplayData();
                RegisterStartupScript(StringMessages.STARTUP_SCRIPT_KEY, 
                    DecorateScript(StringMessages.STARTUP_SCRIPT));
                CreateButton.Attributes.Add("onclick", "SaveButtonClicked();");
                SaveAsFileRadioButton.Attributes.Add("onclick", StringMessages.ON_CLICK_SCRIPT);
                SaveInDatabaseRadioButton.Attributes.Add("onclick", StringMessages.ON_CLICK_SCRIPT);
            }
        }
Posted
Comments
F-ES Sitecore 17-Apr-20 8:01am    
Does SaveButtonClicked get called? When you step through the code line by line at what point does it stop doing what it does in IE?
Swathi_Shri 20-Apr-20 5:46am    
Yes save button gets called.

Once we click the radio button -
Download network template as a file

and click on create , the file gets downloaded.
this happens in IE.
Richard Deeming 21-Apr-20 13:34pm    
Your Javascript has lots of references to document._all. That's not a standard property, and you haven't declared it anywhere in the code you've shown.

If you're actually using document.all, that's a non-standard and deprecated property which may not work in a modern browser.
Document.all - Web APIs | MDN[^]

You're also using document.frames, which is non-standard. It should be window.frames instead:
Window.frames - Web APIs | MDN[^]

You need to check the developer console in Chrome to see if you're getting any Javascript errors.
Swathi_Shri 28-Apr-20 9:18am    
Hi Richard,
I have changed them too. I used document.getElementById in place of document.all

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900