Ajax Update Panel and Export to Excel Functionality

Last post 06-09-2008 9:55 AM by axeman420. 29 replies.

Sort Posts:

  • Ajax Update Panel and Export to Excel Functionality

    03-14-2007, 7:18 PM
    • Loading...
    • axeman420
    • Joined on 11-01-2004, 11:27 AM
    • Posts 42

    Hello all,

     I've run into an issue here. I have a gridview control that I want to export to Excel. All is well when it's on a simple page. The problem lies once I add it to the page I want it on. When I place it under an UpdatePanel it completely stops working. I've search the net and still have not found anything that might fix this issue. I know this is a known issue but does anyone have a fix for it?

    I've already tried the following:

    1. Overriding VerifyRenderingInServerForm

    2. EnableEventValidation="False"

    3. Generating HTMLForm at Runtime (or OnClick)

    Any suggestions? Or is this just not possible?

     Axe

  • Re: Ajax Update Panel and Export to Excel Functionality

    01-27-2008, 8:40 PM
    • Loading...
    • mgh1472
    • Joined on 11-13-2006, 9:24 PM
    • Posts 14

    Dammit I've reproduced this same exact problem.... Did you ever figure out a solution? 

    -Matt
  • Re: Ajax Update Panel and Export to Excel Functionality

    01-27-2008, 10:25 PM

    For exporting data to exce, if you Response.Write() or writer.write() somewhere in code the it wont work

    Because of the way updatepanels manage the DOM elements within them, you cannot use Response.Write() with them.

    http://vijaymodi.wordpress.com/2007/04/13/syswebformspagerequestmanagerparsererrorexception/

    http://weblogs.asp.net/leftslipper/archive/2007/02/26/sys-webforms-pagerequestmanagerparsererrorexception-what-it-is-and-how-to-avoid-it.aspx

    http://forums.asp.net/t/1038252.aspx

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: Ajax Update Panel and Export to Excel Functionality

    01-28-2008, 3:42 PM
    Answer
    • Loading...
    • axeman420
    • Joined on 11-01-2004, 11:27 AM
    • Posts 42

    Alll you need to do is set up the linkbutton or button triggering the export code as a Postbacktrigger on the update panel.

     Axel

  • Re: Ajax Update Panel and Export to Excel Functionality

    01-28-2008, 9:45 PM
    • Loading...
    • mgh1472
    • Joined on 11-13-2006, 9:24 PM
    • Posts 14

    Many thanks that did the trick!!! Wink  You know I really like this forum, its one of a few I actually can get issues resolved...

    <asp:UpdatePanel ID="UpdatePanel3" runat="server">

    <Triggers>

    <asp:PostBackTrigger ControlID="CompletedExcelExport" />

    </Triggers>

    -Matt

    -Matt
  • Re: Ajax Update Panel and Export to Excel Functionality

    02-02-2008, 9:57 PM
    • Loading...
    • mgh1472
    • Joined on 11-13-2006, 9:24 PM
    • Posts 14

    Ok here is something really wierd.  I have a tabcontainer and on tab3 I have a updatepanel with a gridview on it. Using the postbacktrigger I can export the gridview to excel just fine.  Now on tab4 I have another updatepanel with another gridview on it. There is also a postbacktrigger on the updatepanel to export data to excel.  They both run the same export to excel code (passing in the filename and gridview#) but only the first export to excel on tab3 works and the second one on tab4 only displays the EmptyDataTemplate row in excel. Is this some crazy limitation with updatepanels & postbacktriggers like limit 1 per page? Huh?

    -Matt
  • Re: Ajax Update Panel and Export to Excel Functionality

    02-04-2008, 9:51 AM
    • Loading...
    • axeman420
    • Joined on 11-01-2004, 11:27 AM
    • Posts 42

    Matt,

     There isn't a limitation on the number of updatepanels and postbacktriggers per page. I actually have a tabcontainer set up with about 6 tabs and 4 of those contain gridviews that are exported to excel without any problems. Post your code and maybe I can help you figure it out...Include the code that sends the identifying gridview and filename as well...

  • Re: Ajax Update Panel and Export to Excel Functionality

    02-04-2008, 8:30 PM
    • Loading...
    • mgh1472
    • Joined on 11-13-2006, 9:24 PM
    • Posts 14

    Axeman,  sorry it took so long to post back I needed to get the code from my home pc.  Anyway in the code behind I pointed out the issue.  I hate coding while frustrated.  Any help is greatly appreciated!!!!

        <ajaxToolkit:TabContainer ID="TabContainer1" runat="server" AutoPostBack="false" ActiveTabIndex="0">
                 <ajaxToolkit:TabPanel ID="TabPanel1" runat="server" HeaderText="Welcome" Width="100%">
                 <ajaxToolkit:TabPanel ID="TabPanel2" runat="server" HeaderText="Password">
                 <ajaxToolkit:TabPanel ID="TabPanel3" runat="server" HeaderText="Pending Shops">
                    <ContentTemplate>
                        <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
                        <Triggers>
                            <asp:PostBackTrigger ControlID="PendingExcelExport" />                                                                                          
                        </Triggers>
                            <ContentTemplate>
                                <br />                       
                        <asp:GridView ID="GridView2" runat="server" AllowPaging="True" AllowSorting="True"
                            AutoGenerateColumns="False" CellPadding="4" DataKeyNames="shop_id" DataSourceID="SqlDataSource2" Font-Size="Smaller" GridLines="None"
                            ShowFooter="True" Width="100%">
                            <HeaderStyle BackColor="#3378B1" ForeColor="White" />
                            <PagerSettings PageButtonCount="20" />
                            <EmptyDataRowStyle BackColor="LightSteelBlue" ForeColor="Red" />
                            <AlternatingRowStyle BackColor="#3378B1" ForeColor="White" />
                            <EmptyDataTemplate>
                                No pending shops loaded....
                            </EmptyDataTemplate>
                            <EditRowStyle BackColor="Orange" />
                            <Columns>                       
                                <asp:TemplateField HeaderText="ID">
                                    <ItemStyle HorizontalAlign="Left" Wrap="False" />
                                    <HeaderStyle HorizontalAlign="Left" Wrap="False" />
                                    <ItemTemplate>
                                        <asp:Label ID="Shop_idValue" runat="server" Text='<%# Eval("shop_id") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Shop Status" SortExpression="status">
                                    <ItemStyle HorizontalAlign="Left" Wrap="False" />
                                    <HeaderStyle HorizontalAlign="Left" Wrap="False" />
                                    <ItemTemplate>
                                        <asp:Label ID="StatusValue" runat="server" Text='<%# Eval("status") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Shop Type" SortExpression="shop_type">
                                    <ItemStyle HorizontalAlign="Left" Wrap="False" />
                                    <HeaderStyle HorizontalAlign="Left" Wrap="False" />
                                    <ItemTemplate>
                                        <asp:Label ID="ShopTypeValue" runat="server" Text='<%# Eval("shop_type") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Customer" SortExpression="customer">
                                    <ItemStyle HorizontalAlign="Left" Wrap="False" />
                                    <HeaderStyle HorizontalAlign="Left" Wrap="False" />
                                    <ItemTemplate>
                                        <asp:Label ID="CustomerValue" runat="server" Text='<%# Eval("customer") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Agent" SortExpression="agent">
                                    <ItemStyle HorizontalAlign="Left" Wrap="False" />
                                    <HeaderStyle HorizontalAlign="Left" Wrap="False" />
                                    <ItemTemplate>
                                        <asp:Label ID="AgentValue" runat="server" Text='<%# Eval("agent") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Community" SortExpression="community">
                                    <ItemStyle HorizontalAlign="Left" Wrap="False" />
                                    <HeaderStyle HorizontalAlign="Left" Wrap="False" />
                                    <ItemTemplate>
                                        <asp:Label ID="CommunityValue" runat="server" Text='<%# Eval("community") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Partner" SortExpression="partner">
                                    <ItemStyle HorizontalAlign="Left" Wrap="False" />
                                    <HeaderStyle HorizontalAlign="Left" Wrap="False" />
                                    <ItemTemplate>
                                        <asp:Label ID="PartnerValue" runat="server" Text='<%# Eval("partner") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Shop StartDate" SortExpression="shop_startdate">
                                    <ItemStyle HorizontalAlign="Left" Wrap="False" />
                                    <HeaderStyle HorizontalAlign="Left" Wrap="False" />
                                    <ItemTemplate>
                                        <asp:Label ID="ShopStartDateValue" runat="server" Text='<%# FixDate(Eval("shop_startdate","{0:dd-MMM-yyyy HH:mm}")) %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Shop EndDate" SortExpression="shop_enddate">
                                    <ItemStyle HorizontalAlign="Left" Wrap="False" />
                                    <HeaderStyle HorizontalAlign="Left" Wrap="False" />
                                    <ItemTemplate>
                                        <asp:Label ID="ShopEndDateValue" runat="server" Text='<%# FixDate(Eval("shop_enddate","{0:dd-MMM-yyyy HH:mm}")) %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Follow Up" SortExpression="follow_up">
                                    <ItemStyle HorizontalAlign="Left" Wrap="False" />
                                    <HeaderStyle HorizontalAlign="Left" Wrap="False" />
                                    <ItemTemplate>
                                        <asp:Label ID="FollowUpValue" runat="server" Text='<%# Eval("follow_up") %>' Width="100"></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Agent Score" SortExpression="agent_score">
                                    <ItemStyle HorizontalAlign="Left" Wrap="False" />
                                    <HeaderStyle HorizontalAlign="Left" Wrap="False" />
                                    <ItemTemplate>
                                        <asp:Label ID="AgentScoreValue" runat="server" Text='<%# Eval("agent_score") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Password" SortExpression="password">
                                    <ItemStyle HorizontalAlign="Left" Wrap="False" />
                                    <HeaderStyle HorizontalAlign="Left" Wrap="False" />
                                    <ItemTemplate>
                                        <asp:Label ID="PasswordValue" runat="server" Text='<%# Eval("password") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Invoice" SortExpression="invoice">
                                    <ItemStyle HorizontalAlign="Left" Wrap="False" />
                                    <HeaderStyle HorizontalAlign="Left" Wrap="False" />
                                    <ItemTemplate>
                                        <asp:Label ID="InvoiceValue" runat="server" Text='<%# Eval("invoice") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Shop Amount" SortExpression="shop_amount">
                                    <ItemStyle HorizontalAlign="Left" Wrap="False" />
                                    <HeaderStyle HorizontalAlign="Left" Wrap="False" />
                                    <ItemTemplate>
                                        <asp:Label ID="ShopAmountValue" runat="server" Text='<%# FormatCurrency(Eval("shop_amount"),2) %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Shop Paid" SortExpression="customer_paid">
                                    <ItemStyle HorizontalAlign="Left" Wrap="False" />
                                    <HeaderStyle HorizontalAlign="Left" Wrap="False" />
                                    <ItemTemplate>
                                        <asp:Label ID="ShopPaidValue" runat="server" Text='<%# Eval("customer_paid") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                            <PagerStyle HorizontalAlign="Left" />
                        </asp:GridView>
                            <asp:ImageButton ID="PendingExcelExport" runat="server" ImageUrl="images/excel.jpg" ToolTip="Click to export pending shops to Excel..."/>             
                            </ContentTemplate>
                        </asp:UpdatePanel>
                        &nbsp;<br />
             
              <br />
                        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:MSSQLConnectionString %>"
                          
                        </asp:SqlDataSource>
                    </ContentTemplate>
                     <HeaderTemplate>
                         Pending Shops
                     </HeaderTemplate>
                 </ajaxToolkit:TabPanel>            
                 <ajaxToolkit:TabPanel ID="TabPanel4" runat="server" HeaderText="Shops">
                    <ContentTemplate>
                        <asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional">
                        <Triggers>
                            <asp:PostBackTrigger ControlID="CompletedExcelExport" />                                                                                          
                        </Triggers>
                            <ContentTemplate>
                                <br />
                      <ajaxtoolkit:CollapsiblePanelExtender ID="CollapsiblePanelExtender2" runat="server" ExpandControlID="UserTitlePanel" CollapseControlID="UserTitlePanel"
                            TargetControlID="UserBodyPanel" Collapsed="True" TextLabelID="Label1" ExpandedText="Hide Search...." CollapsedText="Show Search"
                            ImageControlID="Image1" CollapsedImage="images/expand_blue.jpg" ExpandedImage="images/collapse_blue.jpg" Enabled="True" />
                      
                      <asp:Panel ID="UserTitlePanel" runat="server" CssClass="collapsePanelHeader">
                          <asp:Image ID="Image1" runat="server" ImageUrl="images/expand_blue.jpg" />&nbsp;&nbsp;
                          <asp:Label ID="Label1" runat="server" Text="Show Search...."></asp:Label>
                      </asp:Panel>
                      <asp:Panel ID="UserBodyPanel" runat="server" CssClass="collapsePanel">
                          <table style="width: 452px">
                              <tr>
                                  <td style="font-size: small; width: 130px; height: 45px">
                                      Start Date:<br />
                                      <asp:TextBox ID="txtStartDate" runat="server" ToolTip="Date Format: dd-mon-yyyy Or mm/dd/yyyy"
                                          Width="90px"></asp:TextBox>
                                      <asp:ImageButton ID="CalImageButton1" runat="server" AlternateText="Click to show calendar"
                                          ImageUrl="~/images/calendar.png" />
                                      <ajaxToolkit:CalendarExtender ID="calendarButtonExtender1" runat="server" CssClass="MyCalendar"
                                          PopupButtonID="CalImageButton1" TargetControlID="txtStartDate" Enabled="True">
                                      </ajaxToolkit:CalendarExtender>
                                  </td>
                                  <td style="font-size: small; width: 130px; height: 45px">
                                      End Date:<br />
                                      <asp:TextBox ID="txtEndDate" runat="server" ToolTip="Date Format: dd-mon-yyyy Or mm/dd/yyyy"
                                          Width="90px"></asp:TextBox>
                                      <asp:ImageButton ID="CalImageButton2" runat="server" AlternateText="Click to show calendar"
                                          ImageUrl="~/images/calendar.png" />
                                      <ajaxToolkit:CalendarExtender ID="calendarButtonExtender2" runat="server" CssClass="MyCalendar"
                                          PopupButtonID="CalImageButton2" TargetControlID="txtEndDate" Enabled="True">
                                      </ajaxToolkit:CalendarExtender>
                                  </td>
                                  <td style="font-size: small; width: 115px; height: 45px">
                                      Agent:<br />
                                      <asp:DropDownList ID="ddlAgent0" runat="server" AppendDataBoundItems="True" DataSourceID="SqlDataSource3"
                                          DataTextField="username" Width="143px">
                                          <asp:ListItem></asp:ListItem>
                                      </asp:DropDownList></td>
                                  <td style="font-size: small; width: 120px; height: 45px">
                                      Community:<br />
                                      <asp:TextBox ID="txtCommunity" runat="server" ToolTip="Type any part of the community name."
                                          Width="135px"></asp:TextBox></td>
                              </tr>
                              <tr>
                                  <td style="font-size: small; width: 100px; height: 45px">
                                      Shop Status:<br />
                                      <asp:DropDownList ID="ddlStatus0" runat="server" Width="143px">
                                          <asp:ListItem></asp:ListItem>
                                          <asp:ListItem Value="Attempted">Attempted</asp:ListItem>
                                          <asp:ListItem Value="Cancelled">Cancelled</asp:ListItem>
                                          <asp:ListItem Value="Completed">Completed</asp:ListItem>
                                      </asp:DropDownList></td>
                                  <td style="font-size: small; width: 120px; height: 45px">
                                      Shop Type:<br />
                                      <asp:DropDownList ID="ddlShopType" runat="server" Width="143px">
                                          <asp:ListItem></asp:ListItem>
                                          <asp:ListItem Value="Competition">Competition</asp:ListItem>
                                          <asp:ListItem Value="New Home">New Home</asp:ListItem>
                                          <asp:ListItem Value="Restaurant">Restaurant</asp:ListItem>
                                      </asp:DropDownList></td>
                                  <td style="font-size: small; width: 125px; height: 45px">
                                      Shop Paid Status:<br />
                                      <asp:DropDownList ID="ddlShopPaidStatus0" runat="server" Width="143px">
                            &