locked
Odd behavior while using a queryextender and a button on my list form. RRS feed

  • Question

  • User1671572222 posted

    I've thrown together a fairly simple dynamic data site (VS2010, .NET 4.0, MSSQL DB). To aid in usability, I added a queryextender to the gridview's datasource that has a searchexpression that checks certain fields to see if they contain a string the user types in a textbox. I've also been asked to add funtionality to export the gridview's displayed results to excel. The problem I'm having is that when I type a string in the "search" textbox then hit enter to search, the function referenced in the "Export To Excel" button also fires. I can't figure out why this is happening, nowhere else in the form am I calling this function other than in the "Export to Excel" button's click event.

    Thursday, January 3, 2013 6:00 PM

Answers

  • User1671572222 posted

    Well this is embarrassing, since I've only got one button on the page (the export to excel button), and I didn't set the UseSubmitBehavior property to false, the button's click event was firing whenever I hit enter. An easy problem to fix now that I know what's causing it.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 7, 2013 10:32 AM

All replies

  • User-330204900 posted

    Hi Rchamblee, I have the same funtionality in my DD sites with no issue it does look like the event handlers are crossed to me maybe you could post you markup.

    Friday, January 4, 2013 5:50 AM
  • User1671572222 posted

    No problem, I'll just post everything in the Content tag. The controls I mentined in my previous post are in bold.

    <asp:DynamicDataManager ID="DynamicDataManager1" runat="server" AutoLoadForeignKeys="true">
            <DataControls>
                <asp:DataControlReference ControlID="GridView1" />
            </DataControls>
        </asp:DynamicDataManager>

        <h2 class="DDSubHeader"><asp:Label runat="server" ID="lblHead"/></h2>
        <br/>
        <table>
            <tr>
                <td><asp:Label runat="server" ID="Label1" Text="Search" CssClass="DDFilter"/></td>
                <td><asp:TextBox runat="server" ID="TextBox1" /></td>
            </tr>
        </table>
        <asp:QueryExtender ID="QE1" runat="server" TargetControlID="GridDataSource">
            <asp:SearchExpression SearchType="Contains" DataFields="NAME, SITE_ID, TECH_PHONE">
                <asp:ControlParameter ControlID="TextBox1"/>
            </asp:SearchExpression>
        </asp:QueryExtender>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <div class="DD">
                    <asp:ValidationSummary ID="ValidationSummary1" runat="server" EnableClientScript="true"
                        HeaderText="List of validation errors" CssClass="DDValidator" />
                    <asp:DynamicValidator runat="server" ID="GridViewValidator" ControlToValidate="GridView1" Display="None" CssClass="DDValidator" />

                    <asp:QueryableFilterRepeater runat="server" ID="FilterRepeater">
                        <ItemTemplate>
                            <asp:Label runat="server" Text='<%# Eval("DisplayName") %>' OnPreRender="Label_PreRender" />
                            <asp:DynamicFilter runat="server" ID="DynamicFilter" OnFilterChanged="DynamicFilter_FilterChanged" /><br />
                        </ItemTemplate>
                    </asp:QueryableFilterRepeater>
                    <br />
                </div>
                <div>
                    <asp:Button ID="btnExp" Text="Export To Excel" runat="server" OnClick="btnExp_Click"/>
                </div>
                <asp:GridView ID="GridView1" runat="server" DataSourceID="GridDataSource" EnablePersistedSelection="true"
                    AllowPaging="True" AllowSorting="True" CssClass="DDGridView"
                    RowStyle-CssClass="td" HeaderStyle-CssClass="th" CellPadding="6" PageSize="50">
                    <Columns>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:DynamicHyperLink runat="server" Action="Edit" Text="Edit"
                                />&nbsp;<asp:LinkButton runat="server" CommandName="Delete" Text="Delete"
                                    OnClientClick='return confirm("Are you sure you want to delete this item?");'
                                />&nbsp;<asp:DynamicHyperLink runat="server" Text="Details" />
                                &nbsp;<asp:LinkButton runat="server" OnClick="lb1Click" Text="Documents" />


                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>

                    <PagerStyle CssClass="DDFooter"/>        
                    <PagerTemplate>
                        <asp:GridViewPager runat="server" />
                    </PagerTemplate>
                    <EmptyDataTemplate>
                        There are currently no items in this table.
                    </EmptyDataTemplate>
                </asp:GridView>

                <asp:EntityDataSource ID="GridDataSource" runat="server" EnableDelete="true" />
                
                <asp:QueryExtender TargetControlID="GridDataSource" ID="GridQueryExtender" runat="server">
                    <asp:DynamicFilterExpression ControlID="FilterRepeater" />
                </asp:QueryExtender>

                <br />

                <div class="DDBottomHyperLink">
                    <asp:DynamicHyperLink ID="InsertHyperLink" runat="server" Action="Insert"><img runat="server" src="~/DynamicData/Content/Images/plus.gif" alt="Insert new item" />Insert new item</asp:DynamicHyperLink>
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>

    Friday, January 4, 2013 9:36 AM
  • User3866881 posted

    Hi,

    I still cannot re-produce your issue……

    Can you be sure that your Search's click hasn't called the function of "ExportGridView button's event"?

    Friday, January 4, 2013 8:45 PM
  • User1671572222 posted

    I'm positive that's not happening. The search should occur when the user hits enter after enteing some text in the textbox.

    Monday, January 7, 2013 9:18 AM
  • User1671572222 posted

    Well this is embarrassing, since I've only got one button on the page (the export to excel button), and I didn't set the UseSubmitBehavior property to false, the button's click event was firing whenever I hit enter. An easy problem to fix now that I know what's causing it.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, January 7, 2013 10:32 AM