这段代码有什么问题?图像按钮必须单击两次才能触发?
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
HttpCookie cookie = new HttpCookie("CultureInfo");
cookie.Value = ImageButton1.CommandArgument;
Response.Cookies.Add(cookie);
Server.Transfer(Request.Path);
Thread.CurrentThread.CurrentCulture = new CultureInfo(cookie.Value);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(cookie.Value);
}
标记位于 Web 控制中,如下所示:
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/_48.png"
CommandArgument="en-US" OnClick="ImageButton1_Click" />
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
HttpCookie cookie = new HttpCookie("CultureInfo");
cookie.Value = ImageButton1.CommandArgument;
Response.Cookies.Add(cookie);
Server.Transfer(Request.Path);
Thread.CurrentThread.CurrentCulture = new CultureInfo(cookie.Value);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(cookie.Value);
}
The markup is in web control, here it is:
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/_48.png"
CommandArgument="en-US" OnClick="ImageButton1_Click" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定在这种情况下是否相关,但是 Server.Transfer 将抛出 ThreadAbortException,就像默认的 Response.Redirect 一样。您的最后 2 条语句将不会被执行。
将它们移至 Server.Transfer 之上,使用 try/catch/finally 块,或者查看 Server.Execute 是否满足您的需求。它将在执行引用的页面后返回。
Not sure if it is pertinent in this case but, Server.Transfer will throw ThreadAbortException, just like the default Response.Redirect. Your final 2 statements will not be executed.
Either move them above the Server.Transfer, use a try/catch/finally block, or see if Server.Execute would meet your needs. It will return after execution of the referenced page.