我有一个网页控件,其中包含一个带有按钮的转发器,该按钮使用命令将项目添加到嵌套转发器
control ->
Rounds - [+] (add group) ->
Groups
据我所知,我需要使用ItemCommand
所以我可以传递我将添加组的轮次ID
的参数,但是当我执行add命令然后刷新页面再次触发命令。
我不希望这种情况发生,有没有办法知道浏览器正在刷新,可能我可以设置cookie或会话变量?
使用重定向似乎不起作用,因为我使用会话变量来存储轮次列表,并确保我在任何时候只有一个这个变量的实例我将其删除并在页面第一时将其添加为新变量打开,这似乎导致列表重置。
以下是ItemCommand
事件的代码。
protected void RoundsRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "AddGroup")
{
if (e.CommandArgument.ToString().AsID() > 0)
{
Control ctrl = e.Item.FindControl("RuleGroupListctrl");
if (ctrl != null && ctrl is RuleGroupList)
{
CompetitionRuleGroup grp = new CompetitionRuleGroup();
CompetitionRound currentRound = Rounds.FirstOrDefault(r => r.Round == e.CommandArgument.ToString().AsID());
grp.CompetitionID = currentRound.CompetitionID;
if (currentRound != null)
currentRound.CompetitionRuleGroups.Add(grp);
}
}
}
}
任何帮助都将不胜感激。
由于
答案 0 :(得分:0)
2条建议。
autopostback=false
模式?为什么不将所有page_load
定义放在
if (!page.ispostback())
除了第一个page_load
之外,每次都会跳过page_load
。
答案 1 :(得分:0)
您可以重定向到ItemCommand
处理程序
Response.Redirect("YourPage.aspx");
什么叫做Post-Redirect-Get(PRG)-Pattern。
http://www.andypemberton.com/engineering/the-post-redirect-get-pattern/