开发者

What is wrong in this code?Image Button has to be clicked twice to fire?

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=开发者_StackOverflow中文版"server" ImageUrl="~/Images/_48.png"  
                 CommandArgument="en-US" OnClick="ImageButton1_Click" /> 


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜