0
我已經添加了一個UpdatePanel
環繞一個GridView並給它兩個觸發器,它們是UpdatePanel之外的按鈕。我無法獲得按鈕單擊事件來觸發GridView異步刷新。ASP.NET UpdatePanel不工作
我敢肯定,數據源正在更新,因爲F5刷新頁面顯示新的數據(這是通過文本框提交)
我也試過編程更新在代碼隱藏文件中UpdatePanel
(UpdatePanel1.Update();
)但是也不這樣做。
這裏是我的代碼:
<%@ 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>
看看這可以幫助你:觸發在UpdatePanel的更新通過控制是在不同的ContentTemplate(http://stackoverflow.com/questions/417131/trigger-an-update-of-the- updatepanel-by-a-control-that-is-in-different-contentpl) – jadarnel27
感謝您的參考,但我無法完全理解它。總結;我有一個GridView在文本框中顯示以前的條目。我希望submitBtn觸發兩個數據被髮送到Gridview的數據源,同時也是Girdview的異步更新。 爲了確保被遲添加觸發器儘可能(根據您的鏈接)我加入他們,當文本框被改變。這不知何故仍然無法工作。無論如何,儘管 – hippo30
首先確定是否有任何錯誤。對於例如有時候這將是由於沒有正確關閉html標籤。 –