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

response.BinaryWrite() stops working on telerik:RadPageView

3 Answers 54 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Abhinav
Top achievements
Rank 1
Abhinav asked on 27 Aug 2011, 01:00 PM
Hi All,

I am facing a problem related to response.BinaryWrite(), it is not working on telerik:RadPageView.
My code is as below.

ASPX:
<telerik:RadPageView ID="vXML" runat="server" CssClass="edit-area">
                    <div class="padded-container">
                        <asp:LinkButton runat="server" EnableViewState="false" class="padded-element-first" OnClientClick="clientButtonClicking();"
                            Text="Download" CommandName="XML" CausesValidation="true" ID="btnExportXML" OnCommand="btnExport_Click" />
                        <label id="btnImportXML" class="padded-element-last" style="cursor: pointer; color: #0E3D4F;
                            text-decoration: underline; display: inline" onclick='toogleDisplays("btnImportXML","divUpldXML"); return false;'>
                            Upload</label>
                        <div id="divUpldXML" style="visibility: hidden; display: inline">
                            <asp:FileUpload CssClass="padded-element-last" EnableViewState="false" runat="server"
                                ID="upldXML" />
                            <asp:RequiredFieldValidator ValidationGroup="grpInputs" ID="vldUpldXml" ControlToValidate="upldXML"
                                runat="server" ErrorMessage="PlaceholderXML is required. Enter valid PlaceholderXML."
                                Text="*" />
                            <asp:RegularExpressionValidator ValidationGroup="grpInputs" Enabled="false" ID="vldRegExpUpldXml"
                                runat="server" ErrorMessage=".xml extension only" ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.xml|.XML)$"
                                ControlToValidate="upldXML" />
                        </div>
                    </div>
                    <tzgcontrols:XmlView Style="width: 97%; overflow: scroll; clip: auto; word-wrap: break-word;"
                        EnableViewState="true" ID="ViewerXML" runat="server" CssClass="XmlFormat placeholder-box" />
                </telerik:RadPageView>


Javascript:

       
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            RadAjax.OnStart(
{
 
    btnExportXML: doNotUseAjax,
    btnExportXSLT: doNotUseAjax,
    btnExportXSD: doNotUseAjax
});
            var cancelAjax = false;
 
            function clientButtonClicking(sender, eventArgs) {
                debugger;
                if (eventArgs.get_item().get_value() == "postback") {
                    cancelAjax = true;
                }
            }
 
            function onRequestStart(ajaxManager, eventArgs)
            {
                alert(cancelAjax);
                alert(eventArgs.EventTarget);
                if ((eventArgs.EventTarget == "btnExportXML") && (cancelAjax)) { alert('TEST'); eventArgs.EnableAjax = false; }
                if ((eventArgs.EventTarget == "btnExportXSD") && (cancelAjax)) { eventArgs.EnableAjax = false; }
 
                //Uncomment the line below in case of a file download.
                cancelAjax = false;
            }
             
        </script>
    </telerik:RadCodeBlock>


CS:

public static void DownloadFile(HttpResponse response, Constants.DownloadFileType type, string fileName, byte[] data)
{
    using (var trace = new TraceManager("Default"))
    {
        try
        {
            response.Clear();
            response.Buffer = true;
            byte[] storage = data;
 
            switch (type)
            {
                case Constants.DownloadFileType.XML:
                    //document is xml
                    response.ContentType = "application/xml";
                    response.AddHeader("Content-Disposition", "attachment;filename=" + fileName + ".xml");
                    break;
 
                case Constants.DownloadFileType.XSLT:
                    //document is xslt
                    response.ContentType = "application/xml";
                    response.AddHeader("Content-Disposition", "attachment;filename=" + fileName + ".xslt");
                    break;
                case Constants.DownloadFileType.XSD:
                    //document is xslt
                    response.ContentType = "application/xml";
                    response.AddHeader("Content-Disposition", "attachment;filename=" + fileName + ".xsd");
                    break;
 
                case Constants.DownloadFileType.DOCX:
                    response.ContentType =
                        "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                    response.AddHeader("Content-Disposition",
                                       "attachment;filename=" + fileName + ".docx");
                    break;
 
                case Constants.DownloadFileType.EMAIL:
                    //document is email
                    response.ContentType = "text/html";
                    response.AddHeader("Content-Disposition",
                                       "attachment;filename=" + fileName + ".html");
                    break;
 
                default:
                    //throw new Exception("Unknown Placeholder type specified.");
                    break;
            }
            response.Cache.SetCacheability(HttpCacheability.NoCache);
            response.BinaryWrite(storage);
            //response.End();
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }
        catch (Exception ex)
        {
            trace.HandleException(ex);
        }
    }
}

Please help to resolve this issue.

3 Answers, 1 is accepted

Sort by
0
Dimitar Terziev
Telerik team
answered on 01 Sep 2011, 03:50 PM
Hello Abhinav,

Could you clarify what exactly is the experienced problem and what you mean by "response.BinaryWrite() stops working on telerik:RadPageView"?

Do you get an exception or other errors on the page?

All the best,
Dimitar Terziev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Abhinav
Top achievements
Rank 1
answered on 02 Sep 2011, 07:17 AM
Hi Dimitar,

I am getting this error.Please help to resolve this issue.
"Microsoft JScript runtime error:
Sys.WebForms.PageRequestManagerParserErrorException: The message received from
the server could not be parsed."
0
Dimitar Terziev
Telerik team
answered on 07 Sep 2011, 02:54 PM
Hi Abhinav,

This problem might appears if the content of the RadPageViewes is ajaxified. Please refer to the following forum post discussing what is the common cause for this error and how to deal with it.

Greetings,
Dimitar Terziev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
General Discussions
Asked by
Abhinav
Top achievements
Rank 1
Answers by
Dimitar Terziev
Telerik team
Abhinav
Top achievements
Rank 1
Share this question
or