【发布时间】:2016-05-18 16:45:37
【问题描述】:
我正在尝试创建一个游戏;当我单击一个按钮时,我需要使用查询字符串转到另一个页面,我需要知道单击了哪个按钮(Button1),以及单击了多少次(Turn)。这是我的代码:
int Turn = 0;
protected void Button1_Click(object sender, EventArgs e)
{
string clickedButton = "Button1";
Turn = Turn ++;
Response.Redirect(string.Format("TheGame.aspx?button={0}&turn={1}", clickedButton , Turn));
}
但问题是,我永远无法改变轮到,它总是保持为 0。我该怎么做?
【问题讨论】:
-
您只需要在每次页面刷新时读取查询中的
Turn值。该页面对服务器的每个请求都会在 0 处重新启动页面类中的 Turn 变量,您需要查看查询字符串并获取 current turn 值并存储到 Turn 变量中。跨度>
标签: c# asp.net query-string