Question

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);
}

Le balisage est en contrôle Web, voici:

<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/Images/_48.png"  
                 CommandArgument="en-US" OnClick="ImageButton1_Click" /> 
Était-ce utile?

La solution

Je ne sais pas s'il est pertinent dans ce cas, mais, Server.Transfer va jeter ThreadAbortException, tout comme le Response.Redirect par défaut. Vos 2 dernières déclarations ne seront pas exécutées.

Soit les déplacer au-dessus du Server.Transfer, utilisez un try / catch / finally bloc, ou si Server.Execute répondrait à vos besoins. Il sera de retour après l'exécution de la page référencée.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top