Setting RadGrid to allow Response writes breaks other telerik controls

2 posts, 0 answers
  1. Thomas
    Thomas avatar
    4 posts
    Member since:
    Aug 2013

    Posted 04 Oct Link to this post

    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.

  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1803 posts

    Posted 07 Oct Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top