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

AJAX call never returns

1 Answer 97 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 2
Andy asked on 19 Apr 2011, 08:44 PM
I have a couple of grids on tabs for each row of a grid in a nested view. The code-behind opens the first record to view the first item. At this point, I can click on the link to download my attachment, but it only works the first time. After that, it hangs and I can't figure out why.

If you can figure out what I need to correct, it would be a tremendous help!

I've created a mini-project that demonstrates the problem. I've substituted 2 XML files for data sources, but, for this demo, the attachment is hard-coded. (It's using a PDF.)

<%@ Page Language="C#" %>
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<script runat="server">
 
    protected void DownloadForShot_ImageButton_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {
        ImageButton btnDownload = (ImageButton)sender;
        GridDataItem dataItem = (GridDataItem)btnDownload.NamingContainer;
        RadGrid Attachments_RadGrid = (RadGrid)dataItem.NamingContainer.NamingContainer;
        Label lblShotID =(Label)Attachments_RadGrid.NamingContainer.FindControl("ShotID_Label");
        try
        {
//NOTE THE HARD CODED VALUE HERE
        System.IO.FileInfo file = new System.IO.FileInfo("C:\\inetpub\\wwwroot\\TestSite\\Images\\TestPDF.pdf");
 
        if (file.Exists)
        {
            Response.ClearContent();
            Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", file.Name));
            Response.AddHeader("Content-Length", file.Length.ToString());
            Response.ContentType = "application/pdf";            // "image/jpeg"
            Response.TransmitFile(file.FullName);
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }
        else
        {
            throw new Exception("There is no attachment for this path or the path is not valid.");
        }
        }
        catch (Exception ex)
        {
            Response.Write("<span style='color:red;'>" + ex.Message + "</span>");
        }
    }
 
    protected void ShotDetail_RadGrid_PreRender(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (ShotDetail_RadGrid.MasterTableView.Items.Count > 0)
            {
                ShotDetail_RadGrid.MasterTableView.Items[0].Expanded = true;
                ShotDetail_RadGrid.MasterTableView.Items[0].ChildItem.FindControl("InnerContainer").Visible = true;
            }
        }
    }
</script>
 
<head runat="server">
    <title>Title</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div id="div_Shots_ShotDetail" style="width:99%; height:1500px; position:absolute;">
            <telerik:RadGrid ID="ShotDetail_RadGrid" runat="server" DataSourceID="XmlDataSource1"
                    AllowPaging="True" Skin="Hay" GridLines="None" ShowStatusBar="True" Width="921px"
                onprerender="ShotDetail_RadGrid_PreRender" >
                <HierarchySettings ExpandTooltip="Show related merch" CollapseTooltip="Collapse merch"></HierarchySettings>
                <ExportSettings IgnorePaging="True">
                    <Pdf PageBottomMargin="0.5in" PageHeight="8.5in" PageLeftMargin="0.35in"
                            PageRightMargin="0.35in" PageTopMargin="0.5in" PageWidth="11in" />
                </ExportSettings>
                <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True">
                    <Selecting AllowRowSelect="True"></Selecting>
                    <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                </ClientSettings>
                <MasterTableView DataSourceID="XmlDataSource1" AutoGenerateColumns="False"
                    AllowCustomPaging="True">
                    <NestedViewTemplate>
                        <asp:Panel runat="server" ID="InnerContainer" CssClass="viewWrap" Visible="false">
                            <telerik:RadTabStrip runat="server" ID="TabStip1" MultiPageID="Multipage1" SelectedIndex="0" Width="884px">
                                <Tabs>
                                    <telerik:RadTab runat="server" Text="Attachments" PageViewID="PageView2" Selected="True">
                                    </telerik:RadTab>
                                </Tabs>
                            </telerik:RadTabStrip>
                            <telerik:RadMultiPage runat="server" ID="Multipage1" SelectedIndex="0" RenderSelectedPageOnly="false" >
                                <telerik:RadPageView runat="server" ID="PageView1">
                                    <asp:Label ID="ShotID_Label" runat="server" Text='<%# Eval("ShotID") %>' Visible="false" />
                                    <asp:Label ID="Error_Label" runat="server"></asp:Label>
                                    <telerik:RadGrid ID="Attachments_RadGrid" runat="server" DataSourceID="XmlDataSource2" GridLines="None">
                                        <MasterTableView AutoGenerateColumns="False" DataSourceID="XmlDataSource2">
                                            <CommandItemSettings ExportToPdfText="Export to PDF" />
                                            <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                                                <HeaderStyle Width="20px" />
                                            </RowIndicatorColumn>
                                            <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                                                <HeaderStyle Width="20px" />
                                            </ExpandCollapseColumn>
                                            <Columns>
                                                <telerik:GridTemplateColumn UniqueName="ColumnDownload">
                                                    <ItemTemplate>
                                                        <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
                                                            <asp:ImageButton ID="DownloadForShot_ImageButton" runat="server" ImageUrl="~/Images/view.gif"
                                                                OnClick="DownloadForShot_ImageButton_Click" />
                                                        </telerik:RadAjaxPanel>
                                                    </ItemTemplate>
                                                </telerik:GridTemplateColumn>
                                                <telerik:GridBoundColumn DataField="AttachmentTitle" HeaderText="Attachments" UniqueName="ColumnAttachment">
                                                </telerik:GridBoundColumn>
                                            </Columns>
                                            <EditFormSettings>
                                                <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                                </EditColumn>
                                            </EditFormSettings>
                                        </MasterTableView>
                                        <FilterMenu EnableImageSprites="False">
                                        </FilterMenu>
                                        <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
                                        </HeaderContextMenu>
                                    </telerik:RadGrid>
 
                                    <asp:XmlDataSource ID="XmlDataSource2" runat="server" DataFile="~/XMLFile2.xml"></asp:XmlDataSource>
                                </telerik:RadPageView>
                                <telerik:RadPageView Runat="server" Width="100%" ID="PageView2">
                                </telerik:RadPageView>
                            </telerik:RadMultiPage>
                        </asp:Panel>
                    </NestedViewTemplate>
                    <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
                    <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn>
                    <ExpandCollapseColumn Visible="True"></ExpandCollapseColumn>
                    <Columns>
                        <telerik:GridBoundColumn DataField="ShotID" HeaderText="ShotID" UniqueName="ShotID"
                            FilterControlAltText="Filter ShotID column" SortExpression="ShotID">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="JobNumber" HeaderText="JobNumber" UniqueName="JobNumber"
                            FilterControlAltText="Filter JobNumber column" SortExpression="JobNumber">
                        </telerik:GridBoundColumn>
                    </Columns>
                <EditFormSettings>
                    <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
                </EditFormSettings>
                    <PagerStyle AlwaysVisible="True" />
                </MasterTableView>
                <PagerStyle AlwaysVisible="True" />
                <FilterMenu EnableImageSprites="False"></FilterMenu>
                <HeaderContextMenu EnableImageSprites="True" CssClass="GridContextMenu GridContextMenu_Default"></HeaderContextMenu>
            </telerik:RadGrid>
 
            <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/XMLFile.xml"></asp:XmlDataSource>
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
        </div>
    </div>
    </form>
</body>
</html>

XML File 1:
<?xml version="1.0" encoding="utf-8" ?>
<tables>
    <tShots ShotID="15736" JobNumber="254960"/>
    <tShots ShotID="15737" JobNumber="254960"/>
    <tShots ShotID="15738" JobNumber="254960"/>
    <tShots ShotID="15739" JobNumber="254960"/>
    <tShots ShotID="15740" JobNumber="254960"/>
    <tShots ShotID="15741" JobNumber="254960"/>
</tables>

XML File 2:
<?xml version="1.0" encoding="utf-8" ?>
<tables>
    <tAttachments ShotID="14394" AttachmentExtension=".jpg" AttachmentPath="~/images/Image1/file1.jpg" AttachmentTitle="File Name 1"/>
    <tAttachments ShotID="15737" AttachmentExtension=".jpg" AttachmentPath="~/images/Image1/file2.jpg" AttachmentTitle="File Name 2"/>
    <tAttachments ShotID="15738" AttachmentExtension=".jpg" AttachmentPath="~/images/Image1/file3.jpg" AttachmentTitle="File Name 3"/>
    <tAttachments ShotID="15739" AttachmentExtension=".jpg" AttachmentPath="~/images/Image1/file4.jpg" AttachmentTitle="File Name 4"/>
    <tAttachments ShotID="15740" AttachmentExtension=".jpg" AttachmentPath="~/images/Image1/file5.jpg" AttachmentTitle="File Name 5"/>
</tables>

1 Answer, 1 is accepted

Sort by
0
Accepted
Mira
Telerik team
answered on 22 Apr 2011, 01:40 PM
Hello Andy,

I have examined your code and noticed that you have wrapped the Download button in a RadAjaxPanel. Due to the limitations of the javascript XmlHttpRequest object used for AJAX, to download or upload files, AJAX needs to be temporarily disabled, so that the page performs a full postback.
You can see how it is done here.

I hope this helps.

Best wishes,
Mira
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Andy
Top achievements
Rank 2
Answers by
Mira
Telerik team
Share this question
or