0

I have added an UpdatePanel to surround a GridView and given it two triggers which are buttons outside the UpdatePanel. I cannot get the button click events to trigger the GridView to refresh asynchronously.

I'm sure the datasource is being updated because an F5 page refresh shows the new data (which is submitted through a textfield)

I've also tried programmatically updating the UpdatePanel in the code behind file ( UpdatePanel1.Update(); ) but that does not do it either.

Here is my code:

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="GamePage.aspx.cs" Inherits="GamePage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <span id="userGuess">
        <asp:Label ID="gameStatusLabel" runat="server" CssClass="guesses" Text="15">   
        </asp:Label>
        <asp:Label ID="guessLabel" runat="server" Text="Enter your guess:" 
            CssClass="guessLabel"></asp:Label>
        <asp:TextBox ID="GuessTxtBx" runat="server" MaxLength="4"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
            ControlToValidate="GuessTxtBx"
            ErrorMessage="Don't forget to guess!" CssClass="error" Visible="True" 
            Display="Dynamic"></asp:RequiredFieldValidator>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
            ControlToValidate="GuessTxtBx"
            ErrorMessage="Your guess must be a four digit number" 
            ValidationExpression="\d{4}"
            CssClass="error" Visible="True" Display="Dynamic"></asp:RegularExpressionValidator>
        <span class="guessBtns">
            <asp:Button ID="SubmitBtn" runat="server" OnClick="SubmitBtn_Click" 
                Text="Submit Guess"/>
            <asp:Button ID="newGameButton" runat="server" OnClick="newGameButton_Click" 
                Text="New Game" /></span>
    </span>
    <div>
        The game history:<br />
        <br />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="false" 
                UpdateMode="Conditional">
            <ContentTemplate>
                <asp:GridView ID="TurnGridView" runat="server" AutoGenerateColumns="False" 
                    DataKeyNames="turnID"
                    DataSourceID="TurnsDataSource1" Height="133px" Width="446px" 
                        CssClass="table3">
                    <Columns>
                        <asp:BoundField DataField="turnID" HeaderText="turnID" 
                            InsertVisible="False" ReadOnly="True"
                            SortExpression="turnID" Visible="False" />
                        <asp:BoundField DataField="gameID" HeaderText="gameID" 
                            SortExpression="gameID" Visible="False" />
                        <asp:BoundField DataField="guess" HeaderText="Your Guess" 
                            SortExpression="guess" />
                        <asp:BoundField DataField="responseBulls" HeaderText="Bulls" 
                            SortExpression="responseBulls" />
                        <asp:BoundField DataField="responseCows" HeaderText="Cows" 
                            SortExpression="responseCows" />
                    </Columns>
                </asp:GridView>
                <asp:ObjectDataSource ID="TurnsDataSource1" runat="server" 
                    SelectMethod="GetTurnsByGameID"
                    TypeName="BusinessTier.Turn"   
                    OldValuesParameterFormatString="original_{0}" 
                    onselecting="TurnsDataSource1_Selecting">
                    <SelectParameters>
                        <asp:Parameter Name="gameID" Type="Int32" />
                    </SelectParameters>
                </asp:ObjectDataSource>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="SubmitBtn" EventName="Click"/>
                <asp:AsyncPostBackTrigger ControlID="newGameButton" EventName="Click" />
            </Triggers> 
        </asp:UpdatePanel>
    </div>
</asp:Content>
Leb
  • 15,483
  • 10
  • 56
  • 75
hippo30
  • 45
  • 1
  • 2
  • 9
  • See if this helps you out: [Trigger an update of the UpdatePanel by a control that is in a different ContentTemplate](http://stackoverflow.com/questions/417131/trigger-an-update-of-the-updatepanel-by-a-control-that-is-in-different-contentpl) – Josh Darnell May 21 '12 at 14:29
  • Thanks for the reference but i couldn't quite pull it off. To summarise; i have a GridView displaying previous entries into a text box. I wanted the submitBtn to trigger both data being sent into the datasource of the Gridview and also a asychronous update of the Girdview. To ensure the triggers were added as late as possible (as per your link) i added them when the text box was changed. This somehow fails to work still. Thanks anyway though – hippo30 May 22 '12 at 00:47
  • First identify if there is any error. For e.g. sometimes it will be due to not proper closing of html tag. – Devendra Kumar Jha Jul 29 '13 at 10:46

1 Answers1

1

You probably got a server side error that is swallowed. To see the error message, the easiest way is to temporary replace your AsyncPostBackTrigger by a PostBackTrigger.

DavRob60
  • 3,517
  • 7
  • 34
  • 56