views:

2978

answers:

3

What is correct sytnax for setting an AsyncPostBackTrigger for an UpdatePanel with an asp:ButtonField from an GridView control?

I need to set an 'AsyncPostBackTrigger' for each asp:ButtonField in my GridView

Here is my source code

<asp:UpdatePanel ID="MyUpdatePanel" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
    <Triggers>
    </Triggers>
    <ContentTemplate>
        <asp:GridView ID="MyGridView" runat="server" AutoGenerateColumns="false">       
            <Columns>        
                <asp:ButtonField ButtonType="Link" CommandName="Button1" SelectText="Click Me!" />        
                <asp:ButtonField ButtonType="Link" CommandName="Button2" SelectText="No Click Me!" />    
            </Columns>
        </asp:GridView>
    </ContentTemplate> 
</asp:UpdatePanel>

Update

I need to keep the UpdateMode and ChildrenAsTriggers attributes set to true because the I have other button contained within the UpdatePanel that do not refresh the UpdatePanel control

A: 

The ChildrenAsTriggers property being set to true will cause any control that causes a postback within the update panel to cause it to refresh. You would only need to use the triggers element if you had a control outside of the update panel you wished to use to trigger the refresh of that update panel. You don't even need the triggers element in this instance.

Lance Harper
see comment addressed to Josh
Michael Kniskern
A: 

Everything that Lance Harper mentioned is true, but you also need to remove the following attribute:

UpdateMode="Conditional"

Having that attribute in place will prevent the automatic wire-up of your client side events. Essentially you are telling ASP.Net that you are going to do this yourself.

Josh
I want to keep the conditional attribute set to true because I have buttons within the panel that do not cause the UpdatePanel to refresh.
Michael Kniskern
A: 

Could you use a template field instead of a command field, and forcibly update (UpdatePanel.Update()) the panel when the command button is clicked?

Matthew Jones
I had the wrong code sample. It should be an asp:ButtonField column instead of asp:CommandField column. I updated my code sample
Michael Kniskern
I think my suggestion would still work. Use a Template field, execute the command when the button is pressed, then update the panel.
Matthew Jones