This is a migrated thread and some comments may be shown as answers.

Setting RadGrid to allow Response writes breaks other telerik controls

1 Answer 104 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Thomas
Top achievements
Rank 1
Thomas asked on 04 Oct 2016, 06:34 PM

I have a RadGrid in an update panel.  I also have a RadWindowManager with several windows.

I have a column in the RadGrid that, when clicked, fires the ItemCommand event of the grid.  In this event I generate a file from data in our database and send it to the browser:

        byte[] s = System.Text.Encoding.ASCII.GetBytes(FileXML);
        this.Response.ClearHeaders();
        this.Response.Buffer = true;
        this.Response.ContentType = "application/octet-stream";
        this.Response.AddHeader("Content-Length", s.Length.ToString());
        this.Response.AddHeader("Content-Disposition", "attachment; filename=\"" + FileName + ".vlt\"");
        this.Response.BinaryWrite(s);
        Response.Flush();
        Response.End();

 

This of course causes an error unless I register the RadGrid as a postback control in Page_Load:

        ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
        scriptManager.RegisterPostBackControl(rgTemplates);

 

However, I have another column in this same grid that, when clicked, displays a RadWindow.  The code-behind in the ItemCommand event is:

        if (e.CommandName == "Upload")
        {
            HiddenField hdnTemplateUploadID = (HiddenField)e.Item.FindControl("hdnTemplateUploadID");
            string UploadID = hdnTemplateUploadID.Value;

            string script = "OpenTemplateReplace('" + UploadID + "');";
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "ShowUploadWin", script, true);
        }

which calls the javascript function:

    function OpenTemplateReplace(UploadID) {
        var oManager = GetRadWindowManager();
        $('[id*="hdnReplaceTemplateUploadID"]').val(UploadID);
        radWin = oManager.GetWindowByName("rwReplaceTemplate");
        radWin.setSize(500, 175);
        radWin.set_behaviors(Telerik.Web.UI.WindowBehaviors.Close);
        radWin.show();
        radWin.center();
        return false;
    }

When the RadGrid is registered as a postback control, this fails because the oManager ends up being undefined.  

I also have a RadAsyncUpload control (in the same UpdatePanel as the RadGrid) and after I click the column and get the javascript error described above, the RadAsyncUpload control is no longer shown.

Is there some workaround or something to avoid having to register the RadGrid as a postback control and still be able to send a file via the Response?  I'm trying to avoid actually creating the files and just having the column be a link to the file.

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 07 Oct 2016, 10:47 AM
Hello Thomas,

You can enable the AJAX for RadGrid by wrapping it within a RadAjaxPanel and disabling the AJAX conditionally, as demonstrated in the following help topic:
As you will notice, in the condition for disabling the AJAX you will only have to use the correct ID, corresponding to the button that will initiate the command.

You could also take a look at the documentation regarding the GridAttachmentColumn:
Hope this helps.


Best Regards,
Konstantin Dikov
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Thomas
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or