views:

379

answers:

1

I have a GridView control on a page with a Panel that has a DefaultButton. I am trying to get the "Update" button to work with the Enter key when a user edits a row. It works fine with the mouse. When I click on "Update", the row reverts back to View mode and the updated value is shown.

When the GridView is in the Panel, the Panel's default button (which submits the page) fires when I press Enter, before the RowCommand is even handled, and the update is lost.

When the GridView is not in the Panel, some other seemingly random button in the Panel fires, but not the "Update" button in my row's EditItemTemplate. Specifically, there is a CalendarExtender on the page, and the extender's popup button fires. Totally not what I want.

How can I get this to behave correctly?

Here is the structure of my mark-up code:

<asp:Panel ID="Panel1" runat="server" DefaultButton="btnSubmit">

    <!--Form with controls-->

    <asp:ImageButton ID="btnWSPODateCal" runat="server" />
    <!--this button fires when I press enter while editing a grid row:-->
    <ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" 
    TargetControlID="tbPODate" PopupButtonID="btnWSPODateCal" />

    <!--more controls-->

    <div class="button_row">
        <asp:ImageButton ID="btnCancel" runat="server" />
        <asp:ImageButton ID="btnSubmit" OnClick="btnSubmit_Click" />
    </div>
</asp:Panel>
<asp:GridView runat="server">
    <Columns>
        <asp:TemplateField>
            <EditItemTemplate>
                <asp:ImageButton CommandName="MyUpdate" 
                    ID="btnSubmitRow" runat="server"  
                    CommandArgument="<%# ((GridViewRow) Container).DataItemIndex %>" /> 
A: 

Give this a try. This is just a guess.

<asp:GridView runat="server">
<Columns>
    <asp:TemplateField>
        <EditItemTemplate>
            <asp:Panel ID="Panel2" DefaultButton="btnSubmitRow" runat="server">
                <asp:ImageButton CommandName="MyUpdate" 
                    ID="btnSubmitRow" runat="server"  
                    CommandArgument="<%# ((GridViewRow) Container).DataItemIndex %>" />
            </asp:Panel>  

You will probably have to put a panel in each of the columns in the GridView. The only thing that might be a problem is the Panel being able to "find" the button inside the GridViewRow.

Also have you tried?

<asp:Panel ID="Panel2" DefaultButton="btnSubmitRow" runat="server">
    <asp:GridView runat="server">
        <Columns>
        <asp:TemplateField>
            <EditItemTemplate>
                <asp:ImageButton CommandName="MyUpdate" 
                    ID="btnSubmitRow" runat="server"  
                    CommandArgument="<%# ((GridViewRow) Container).DataItemIndex %>" />
...
    </asp:GridView>
</asp:Panel>
jWoose
The way you are showing it does not work, because the panel in teh GridView cannot reference the default button by id. I would have to handle this in the onrowdatabound event - too much of a hassle. My workaround is to just fresh the page via scriptmanager.
cdonner
I figured this would be the case. Just thought I would throw it out there.
jWoose