我有一个显示游戏列表的页面(videogames.aspx) 我在更新面板中有一个DataGrid,它使用usercontrol来显示每个视频游戏。 (game.ascx)在我的视频游戏页面中使用。
在这个用户控件中,我可以在游戏中说出进展(完成,玩等等......使用asp按钮)
现在我想在显示列表时对游戏进行评级。 为此,我使用http://www.wbotelhos.com/raty/
我创建了另一个usercontrol(对于rate)。 我在game.ascx usercontrol中使用了这个usercontrol。
第一次加载页面时我没有问题(显示当前的速率) 我决定在第一场比赛中改变我的比率,尝试使用webmethods在数据库中保存好,并通过javascript在屏幕上显示。
现在我决定改变我在第二个视频游戏中的进展,此时(回发)我的第一个游戏的评级又回到了我的旧评级值......
我的印象是我的updatepanel保留了ViewState中的旧值吗?
我如何摆脱这种情况?
VideoGames.aspx:
<asp:UpdatePanel ID="Update" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DataGrid ID="dgJeux" runat="server" AutoGenerateColumns="false" OnItemDataBound="dgJeux_ItemDataBound" AllowPaging="true" PagerStyle-Position="TopAndBottom"
PageSize="10" GridLines="None" CssClass="table" ShowHeader="false" OnPageIndexChanged="dgJeux_PageIndexChanged">
<PagerStyle Mode="NumericPages" HorizontalAlign="Right" CssClass="paginationASP"/>
<Columns>
<asp:BoundColumn DataField="jeu_id" Visible="false"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Jeu" ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle">
<ItemTemplate>
<UC:UCJeu ID="ucJeu" runat="server"></UC:UCJeu>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</ContentTemplate>
</asp:UpdatePanel>
我的game.ascx:
<table>
<tr>
<td><UC:UCNote ID="ucNote" runat="server"></UC:UCNote></td>
<td class="pull-right">
<asp:Repeater ID="rptAvancementJeu" runat="server" Visible="false" OnItemDataBound="rptAvancementJeu_ItemDataBound">
<HeaderTemplate>
<div class="btn-group" data-toggle="buttons-checkbox">
</HeaderTemplate>
<ItemTemplate>
<asp:Button ID="butAvancementJeu" CssClass="btn btn-success" runat="server" Text='<%# Eval("jeuavancement_libelle") %>' OnCommand="butAvancementJeu_OnCommand" CommandName="ChangerAvancement" Width="85"/>
</ItemTemplate>
<FooterTemplate>
</div>
</FooterTemplate>
</asp:Repeater>
</tr>
</table>
我的GameRate.Ascx:
<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
function EndRequestHandler(sender, args) {
if (args.get_error() == undefined) {
$(document).ready(function() {
$('#<%= noteMoyenne.ClientID %>').raty({
score: function () {
return $('#<%= noteMoyenne.ClientID %>').attr('data-rating');
},
readOnly: true
});
$('#<%=noteUtilisateur.ClientID %>').raty({
half: true,
click: function (score, evt) {
var contexte = new Array('<%= noteUtilisateur.ClientID %>', '<%= noteMoyenne.ClientID %>');
PageMethods.AffecteNoteEtRetourneNoteMoyenne($('#<%= hfObjectID.ClientID %>').val(), score, AffecterNoteEtMoyenne, null, contexte)
},
score: function () {
return $('#<%= noteUtilisateur.ClientID %>').attr('data-rating');
}
});
});
}
}
</script>
<table>
<asp:Panel ID="pnlNoteUtilisateur" runat="server" Visible="false">
<tr>
<td>
Note :
</td>
<td>
<div id="noteUtilisateur" runat="server"></div>
<asp:HiddenField ID="hfObjectID" runat="server" />
</td>
</tr>
</asp:Panel>
<tr>
<td>
Moyenne :
</td>
<td>
<div id="noteMoyenne" runat="server"></div>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Label ID="lblNombreNotes" runat="server" Text="(pas de note)"></asp:Label>
</td>
</tr>
</table>
raty生成的html的例子:
<div id="ctl00_content_dgJeux_ctl03_ucJeu_ucNote_noteUtilisateur" data-rating="0.5" style="cursor: pointer; width: 100px;">
<img src="../img/stars/star-half.png" alt="1" title="Beurk">
<img src="../img/stars/star-off.png" alt="2" title="Mauvais">
<img src="../img/stars/star-off.png" alt="3" title="Pas mal">
<img src="../img/stars/star-off.png" alt="4" title="Bon">
<img src="../img/stars/star-off.png" alt="5" title="Addictif">
<input type="hidden" name="score" value="0.5">
</div>
它使用data-rating属性来显示评级值。就我而言,在我的新费率之后,价值将是3.5。我的webmethod调用很好,值保存在数据库中。新的数据评级在html中更改。当我希望改变另一场比赛的游戏进程时,问题就开始了。第一场比赛的旧比率价值在回发后回归......
非常感谢你的帮助......我迷失了