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

Web page "frozen" after export to Excel

11 Answers 188 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Celeste
Top achievements
Rank 1
Celeste asked on 09 Dec 2010, 03:00 PM
Dear Form,

I have an ajaxified radgrid that I successfully export to Excel, however, after I close the excel file and return to the web page, all the controls are frozen and I have to refresh the page to get anything working. How can I correct that?

I am working in VS2008 with Q2 2010 release, C#.

Thanks,
Celeste

11 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 09 Dec 2010, 10:43 PM
Hello Celeste,

Indeed this is weird behavior, however I'm unable to reproduce it on my end. Could you please provide some instructions as to how to recreate your scenario?

Kind regards,
Daniel
the Telerik team
Browse the vast support resources we have to jumpstart 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.
0
Celeste
Top achievements
Rank 1
answered on 10 Dec 2010, 03:54 PM
Markup:

 

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<script type="text/javascript
    function onRequestStart(sender, args) {
        
if (args.get_eventTarget().indexOf("btnExcelExport") >= 0)
        args.set_enableAjax(
false);
    }
</script>

 

 

 

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" ClientEvents-OnRequestStart="onRequestStart">
    <
AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGrid1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                
<telerik:AjaxUpdatedControl ControlID="blistMessages" LoadingPanelID="RadAjaxLoadingPanel1" /> 
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>

 

 

 

<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="WebBlue" MinDisplayTime="100" IsSticky="true" Transparency="30" height="50px" />

 

 

 

<telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1" LoadingPanelID="RadAjaxLoadingPanel1"> 
    
<table border="0" cellpadding="0" cellspacing="0" width="100%">
        <
tr>
            <td width="2%">&nbsp;</td>
            
<td width="35%">
                <asp:Label ID="Label1" runat="server" Text="xxxxx" ForeColor="WhiteSmoke" Font-Size="X-Large" 
                    style="font-stretch:expanded; font-weight:400; font-size-adjust:-1" Font-Names="Arial" EnableTheming="false" /><br /><br /> 
            </td> 
            <td align="left"><asp:BulletedList ID="blistMessages" runat="server" ForeColor="WhiteSmoke" Font-Size="Small" /> </td>
        
</tr>
    </table>

 

 

 

 

<telerik:RadGrid ID="RadGrid1" runat="server"
    AllowFilteringByColumn="True"
    AllowPaging="true"
    AllowSorting="True"
    AutoGenerateColumns="False" 
    EnableTheming="false" 
    EnableViewState="true" 
    Font-Size="XX-Small"
    GridLines="None" 
    HorizontalAlign="Left"
    OnExcelExportCellFormatting="RadGrid1_ExcelExportCellFormatting"
    OnGroupsChanging="RadGrid1_GroupsChanging"
    OnInit="RadGrid1_Init"
    OnItemCommand="RadGrid1_ItemCommand" 
    OnItemCreated="RadGrid1_ItemCreated"
    OnNeedDataSource="RadGrid1_OnNeedDataSource" 
    ShowGroupPanel="True" 
    Skin="WebBlue"
    Width="1144px" 
    PageSize="2000">
<ExportSettings OpenInNewWindow="true" IgnorePaging="true" FileName="xxxxx" ExportOnlyData="true" Excel-Format="Html" />
<PagerStyle Position="Top" AlwaysVisible="true" />
<MasterTableView Width="100%" GroupLoadMode="Server" TableLayout="Auto" HeaderStyle-HorizontalAlign="Center" 
    HeaderStyle-VerticalAlign="Middle" HeaderStyle-Font-Bold="true" HeaderStyle-Font-Size="Small" HeaderStyle-Wrap="true" DataKeyNames="" 
    CommandItemDisplay
="Top">
<CommandItemTemplate >
    <table width="100%" cellpadding="1" cellspacing="0" border="0">
        <tr><td width="95%"><asp:Button ID="btnExpandAll" Text="Expand All" Runat="server" CommandName="ExpandAll" /></td>
            <td align="right">
                <
asp:ImageButton ID="btnExcelExport" runat="server" ImageUrl="~/Images/excel.jpg" 
                    CommandName="ExportToExcel" ToolTip="Export to Excel" />
            </
td>
        </tr>
    </table>
</CommandItemTemplate>
<Columns>
    <telerik:GridBoundColumn DataField="zzz" UniqueName="zzz" Visible="false" />
    <telerik:GridTemplateColumn DataField="xxx" HeaderText="xxx" UniqueName="xxx" GroupByExpression="xxx Group By xxx" SortExpression="xxx">
        <FilterTemplate>
            <telerik:RadComboBox ID="rcbxxx" DataSourceID="SDSxxx" EnableTheming="false" DataTextField="xxx" Font-Size="X-Small" 
                    DataValueField="xxx" Height="200px" Width="140px" AppendDataBoundItems="true" 
                    SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("xxx").CurrentFilterValue %>
                    runat="server" OnClientSelectedIndexChanged="xxxChanged" EnableAutomaticLoadOnDemand="False">
                <Items>
                    <telerik:RadComboBoxItem EnableTheming="false" Font-Size="X-Small" />
                </Items>
            </telerik:RadComboBox>
        <telerik:RadScriptBlock ID="rsbxxx" runat="server">
            <script type="text/javascript">
                    function xxxChanged(sender, args) {
                        var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                        tableView.filter(
"xxx", args.get_item().get_value(), "EqualTo");
                    }
            </script>
        </telerik:RadScriptBlock>
    </FilterTemplate>
    <ItemTemplate>
        <%# Eval("xxx")%>
        </ItemTemplate>
    </telerik:GridTemplateColumn>
    <telerik:GridTemplateColumn DataField="yyy" HeaderText="yyy" UniqueName="yyy" 
        GroupByExpression="yyyGroup By yyy"SortExpression="yyy">
        <FilterTemplate>
            <telerik:RadComboBox ID="rcbyyy" DataSourceID="SDSyyy" EnableTheming="false" DataTextField="yyy" Font-Size="X-Small" 
                DataValueField="yyy" Height="200px" Width="120px" AppendDataBoundItems="true"
                
SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("yyy").CurrentFilterValue %>' runat="server" 
                OnClientSelectedIndexChanged
="yyyChanged" EnableAutomaticLoadOnDemand="False">
                
<Items>
                    <telerik:RadComboBoxItem EnableTheming="false" Font-Size="X-Small" />
                </Items>
            </telerik:RadComboBox>
            <telerik:RadScriptBlock ID="rsbyyy" runat="server">
                <script type="text/javascript">
                    function yyyChanged(sender, args) {
                        var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                        tableView.filter(
"yyy", args.get_item().get_value(), "EqualTo");
                    }
                </script>
        
    </telerik:RadScriptBlock>
         </FilterTemplate>
        <ItemTemplate>
            <%# Eval("yyy")%>
        </ItemTemplate>
    </telerik:GridTemplateColumn>
</Columns> 
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" VerticalAlign="Middle" />
</MasterTableView>

 

 

    <ClientSettings AllowGroupExpandCollapse="True" ReorderColumnsOnClient="True" AllowDragToGroup="True" AllowColumnsReorder="True" >
    
</ClientSettings>
    <GroupingSettings ShowUnGroupButton="true" />
</telerik:RadGrid>

 

 

 

</telerik:RadAjaxPanel>
<asp:SqlDataSource ID="SDSxxx" runat="server" ConnectionString="<%$ ConnectionStrings:xxx%>" SelectCommand="usp_xxx" SelectCommandType="StoredProcedure"></asp:SqlDataSource>

 

 

 

<asp:SqlDataSource ID="SDSyyy" runat="server" ConnectionString="<%$ ConnectionStrings:yyy%>" SelectCommand="[usp_yyy]" SelectCommandType="StoredProcedure"></asp:SqlDataSource>

 

 

 

 

</

 

asp:Content>

 

CODE BEHIND:

namespace

 

UI.Reports

 

{

    public partial class Report : System.Web.UI.Page
    {
        bool isExport = false;
        bool isCollapseText = false;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.RadGrid1.Rebind();
                CollapseAll();
            }
            else
            {
                Control c = GetPostBackControl(this);
                if (c.ID == "btnExpandAll")
                {
                    Button b = (Button)c;
                    if (String.Compare(b.Text, "Expand All") == 0)
                    {
                        ExpandAll();
                        b.Text =
"Collapse All";
                    }
                    else
                    {
                        CollapseAll();
                            b.Text =
"Expand All";
                    }
                }
                else
                {
                    this.RadGrid1.Rebind();
                }
            }
        }
        private void CollapseAll()
        {
            foreach (GridItem item in RadGrid1.MasterTableView.Controls[0].Controls)
            {
                if (item is GridGroupHeaderItem)
                {
                    item.Expanded =
false;
                }
            }
        }

        private void ExpandAll()
        {
            foreach (GridItem item in RadGrid1.MasterTableView.Controls[0].Controls)
            {
                if (item is GridGroupHeaderItem)
                {
                    item.Expanded =
true;
                }
            }
        }  

 

 

DataSet ds = new DataSet("DataSetReports");

 

 

 

protected void RadGrid1_OnNeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    SqlCommand myCommand = new SqlCommand("usp_xxx");
    myCommand.CommandType =
CommandType.StoredProcedure;
    SqlConnection myConnection = new SqlConnection(DataBase.ConnectionString);
    myCommand.Connection = myConnection;
    SqlDataAdapter da = new SqlDataAdapter(myCommand);
    da.Fill(ds,
"xxx");
    RadGrid1.DataSource = ds.Tables[
"xxx"];
}

 

 

 

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridFilteringItem && isExport)
        e.Item.Visible =
false;

    GridCommandItem
item = e.Item as GridCommandItem;
    if (item != null)
    {
        if (isCollapseText)
        {
            Button b = (Button)item.FindControl("btnExpandAll");
            b.Text =
"Collapse All";
        }
     }
}

 

 

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToExcelCommandName)
        {
            isExport =
true;
            RadGrid1.MasterTableView.GridLines =
GridLines.Both;
            RadGrid1.ExportSettings.OpenInNewWindow =
true;
            RadGrid1.ExportSettings.ExportOnlyData =
true;
            RadGrid1.ExportSettings.IgnorePaging =
true;
            foreach (GridItem commandItem in RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem))
            {
                commandItem.Visible =
false;
            }
            RadGrid1.MasterTableView.ExportToExcel(); 
        }
        string msg;
        if (e.CommandName == Telerik.Web.UI.RadGrid.FilterCommandName)
        {
            Pair filterPair = (Pair)e.CommandArgument;
            msg =
String.Concat("Filter: '", filterPair.First, "' for ", filterPair.Second, "; ");
            string thisColumnName = filterPair.Second.ToString();
            RadComboBox thisRCB = ((RadComboBox)(e.Item as GridFilteringItem)[filterPair.Second.ToString()].Controls[1]);
            string filterPattern = thisRCB.SelectedValue;
            msg =
String.Concat(msg, "Search Pattern: '", filterPattern, "'");
            // if there is an item in the list that starts with "Filter: " and the same first 11 chars of filterPair.first, then delete it
            String filterColumn = filterPair.Second.ToString();
            for (int i = 0; i < blistMessages.Items.Count; i++)
            {
                ListItem li = blistMessages.Items[i];
                if (li.Text.Contains(filterPair.Second.ToString()))
                {
                    blistMessages.Items.Remove(li);
                }
            }
            if (String.Compare(filterPattern, String.Empty) != 0)
            {
                AddMessageToList(msg);
            }
            isCollapseText =
true;
        }
    }

private
void AddMessageToList(string message)
        {
        ListItem li = new ListItem();
        li.Text = message;
        blistMessages.Items.Add(li);
    }

protected
void RadGrid1_Init(object sender, EventArgs e)
    {
    GridFilterMenu menu = this.RadGrid1.FilterMenu;
    int i = 0;
    while (i < menu.Items.Count)
    //while (i < 7)    
    {
        if (menu.Items[i].Text == "NoFilter" ||
        menu.Items[i].Text ==
"Contains" ||
        menu.Items[i].Text ==
"DoesNotContain" ||
        menu.Items[i].Text ==
"StartsWith" ||
        menu.Items[i].Text ==
"EndsWith" ||
        menu.Items[i].Text ==
"EqualTo" ||
        menu.Items[i].Text ==
"NotEqualTo")
        { i++;}
        else
        { menu.Items.RemoveAt(i);}
      }
}

protected
void RadGrid1_ExcelExportCellFormatting(object source, ExcelExportCellFormattingEventArgs e)
{
    switch (e.FormattedColumn.UniqueName)
    {
        case "xxx": e.Cell.Style["mso-number-format"] = @"0000"; break;
    }
}

 

protected void RadGrid1_GroupsChanging(object source, GridGroupsChangingEventArgs e)

 

{

 

}

}

}

 

 

0
Adnan AlSmail
Top achievements
Rank 1
answered on 15 Dec 2010, 09:36 AM
Hi
I am facing the same problem. I would appreciate it if any one can help on this problem.
0
Daniel
Telerik team
answered on 16 Dec 2010, 10:02 AM
Hello Adnan and Celeste,

In this case you have to hide the loading panel manually.
<script type="text/javascript">
    function removePanel()
    {
        $telerik.findControl(document, "RadAjaxLoadingPanel1").hide();
    }
 
    function onRequestStart(sender, args)
    {
        if (args.get_eventTarget().indexOf("btnExcelExport") >= 0)
        {
            setTimeout(removePanel, 10);
            args.set_enableAjax(false);
        }
    }
</script>

Let me know whether this works for you.

Regards,
Daniel
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.
0
Celeste
Top achievements
Rank 1
answered on 16 Dec 2010, 02:55 PM

Daniel,

Well, it doesn't really work properly - when I return to the page the ajax loading panel is no longer enabled and I get full page postbacks. Can it be re-enabled?

Celeste

0
Adnan AlSmail
Top achievements
Rank 1
answered on 18 Dec 2010, 06:15 AM
Thank you for your reply.
Your solution does not work. It didn't even unfreeze the screen  in my application.
If you can provide working sample code, that would be great. Thank you anyway.
0
Daniel
Telerik team
answered on 21 Dec 2010, 02:14 PM
This is a workaround for a specific setup. You won't need this code in normal circumstances. In the code-snippet below, you have two Ajax controls ajaxifying the same content - this is redundant, error-prone and generally not recommended approach.

Regards,
Daniel
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.
0
Celeste
Top achievements
Rank 1
answered on 21 Dec 2010, 02:51 PM

Daniel,

Perhaps you could enlighten me about how two controls have ajaxified the same content, then. I'm not sure from your reply what exactly isn't correct in my code page. It would be very much appreciated.

Thanks,

Celeste

0
Accepted
Daniel
Telerik team
answered on 21 Dec 2010, 03:37 PM
Hello Celeste,

In this case, RadGrid resides in a RadAjaxPanel which will effectively ajaxify the control. On the other hand you also have RadAjaxManager that is configured so that RadGrid updates itself.
I recommend that you use either RadAjaxManager or RadAjaxPanel, but not both.

Let me know if you need more information.

Best regards,
Daniel
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.
0
Celeste
Top achievements
Rank 1
answered on 22 Dec 2010, 05:46 PM
Daniel,

Thank you! This works perfectly now.

Celeste
0
Howard
Top achievements
Rank 1
answered on 28 Mar 2013, 05:10 PM
This worked for me. I have been looking for a solution and finally found it. Thanks.
            
        Howard at Hanlon Investment Management
Tags
Grid
Asked by
Celeste
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Celeste
Top achievements
Rank 1
Adnan AlSmail
Top achievements
Rank 1
Howard
Top achievements
Rank 1
Share this question
or