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>
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
.