【问题标题】:Write & Read cookie within an updatepanel in asp.net在 asp.net 的更新面板中写入和读取 cookie
【发布时间】:2019-10-02 14:56:54
【问题描述】:

我创建了一个简单的 asp.net webform 项目。尝试在 updatepanel 中的 button_click 事件上读取/写入 cookie。

按钮的层次顺序:

UpdatePanel > Repeater > Button

按钮点击情况:

按钮点击是工作轮。触发器正在工作。当我试图在按钮单击上创建 cookie 时,它​​不起作用。你知道为什么吗?

按钮点击:

protected void mybutton_Click(object sender, EventArgs e)
{
  Button mybutton = sender as Button;
  RepeaterItem rpt = mybutton.NamingContainer as RepeaterItem;
  if(rpt != null)
  {
     HttpCookie newcookie = new HttpCookie("test");
     newcookie.Value= "testvalue";
     Response.Cookie.Add(newcookie);
  }
}

【问题讨论】:

    标签: asp.net cookies updatepanel httpcookie aspbutton


    【解决方案1】:

    我已经搜索并尝试了代码。但仍然有同样的问题。问题与代码无关。代码运行良好。清理您的解决方案,重新启动 Visual Studio。如果 IIS 正在运行,请停止它。

    打开您的项目,您将看到问题消失。

    它对我有用。我希望你这样做。

    【讨论】:

      猜你喜欢
      • 2017-09-02
      • 2019-01-05
      • 2011-06-25
      • 1970-01-01
      • 2018-04-15
      • 1970-01-01
      • 1970-01-01
      • 2013-05-21
      • 1970-01-01
      相关资源
      最近更新 更多