IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

ASP.NET Discussion :

Problème AJAX/Ajout eventHandler


Sujet :

ASP.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de Nixar
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    302
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 302
    Par défaut Problème AJAX/Ajout eventHandler
    Bonjour à tous,
    Désolé d'avance pour les explications un peu longues liées à ce problème, mais je préfère donner toutes les infos... D'autant que je suis un peu désemparé....

    J'ai créé une visionneuse photo dont voici une image ci-dessous (dev) :



    Le principe est assez simple : le panel vert horizontal est chargé avec les miniatures de la galerie photo observée. Lors du clic sur une de ces miniatures, le panel Blanc en haut et à gauche est mis à jour avec l'affichage (via un objet flash) de la photo en grand.
    Lors du clic sur le bouton "caddie", la photo en cours de visualisation est ajoutée au panier (le panel bleu) avec un user control (dont le code est ci dessous) qui contient un bouton auquel j'affecte l'événement de suppression via un event handler..
    Lors du clic sur le bouton sans image en bas du panier, on est redirigé vers la finalisation de commande (pas de souci avec ca).

    Pour faire ça de façon un peu élégante, j'ai créé autant d'UpdatePanel que de conteneurs décrits ci-dessus. L'idée était de mettre ces UpdatePanel en Update conditionnel que je déclenche par le code. Je pense que ce que j'ia fait n'est pas optimisé, n'hésitez pas à me faire de remarques sur l'algo ou sur le développement (je ne suis pas développeur).

    Mon problème est le suivant : Tout fonctionne à une exception près, j'ai besoin de cliquer 2 fois (pas double clic, mais 2 clics bien distincts) sur la croix rouge d'un des users controls du panier pour le supprimer effectivement. Mieux, si je clique sur une croix rouge d'un des users control 1 fois (par exemple celui de la photo7 sur l'image), et que je clique la seconde fois sur une autre croix rouge (la photo 6), le dernier contrôle (celui de la photo 6) sur lequel j'ai créé est supprimé.
    Bref, mon code se comporte comme s'il fallait que je donne une sorte de focus à mon UpdatePanel avant de pouvoir faire une action dedans...

    Voici le code asp.net :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Visionneuse.aspx.cs" Inherits="Visonneuse" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <link rel="stylesheet" type="text/css" href="~/css/StyleSheet.css"/> <link />
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
            <asp:Panel ID="Panel2" runat="server" Height="50px" HorizontalAlign="Right" Width="1000px">
                <asp:Label ID="LabelTitreGalerie" runat="server" Style="clear: right; float: right"
                    Text="Label"></asp:Label>
                <asp:Panel ID="Panel3" runat="server" Height="50px" HorizontalAlign="Left" Style="clear: left;
                    float: left" Width="125px">
                    <asp:ImageButton ID="ImageButtonFr" runat="server" OnClick="ImageButtonFr_Click" />
                    <asp:ImageButton ID="ImageButtonEn" runat="server" OnClick="ImageButtonEn_Click" /></asp:Panel>
            </asp:Panel>
            <div style="width: 1000px; height: 800px" class="AligneMilieu">
                <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                    <ContentTemplate>
                        <asp:Panel ID="PanelPhotoPresentation" runat="server" BackColor="#C0C000" CssClass="HautGauche" Height="600px" Width="600px">
                        <object type="application/x-shockwave-flash" data="presentation.swf?photo=<%=AccesseurPhotoAAfficher%>" width="600" height="600">
                            <param name="movie" value="<%=AccesseurPhotoAAfficher%>" />
                        </object> 
                    </asp:Panel>
                </ContentTemplate>
                </asp:UpdatePanel>
                <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                    <ContentTemplate>
                        <asp:Panel ID="PanelInfoPhotos" runat="server" BackColor="Yellow" CssClass="PlusADroite" Height="150px"
                        Width="400px">
                            <asp:Label ID="Label1" runat="server" CssClass="TitreEncart" Text="Informations sur la photo"></asp:Label>&nbsp;<br />
                            <br />
                            <asp:Panel ID="Panel1" runat="server" Height="50px" Width="400px">
                                <asp:Label ID="LabelNom" runat="server"></asp:Label><br />
                                <asp:UpdateProgress ID="UpdateProgressInfoPhotos" runat="server" DisplayAfter="100" DynamicLayout="true">
                                    <ProgressTemplate>
                                        <asp:Image ID="Image2" runat="server" ImageAlign="Middle" ImageUrl="~/images/ajax-loader-DDL.gif" />
                                        Mise à jour des informations de la photo sélectionnée...
                                    </ProgressTemplate>
                                </asp:UpdateProgress>
                                <br />
                                <asp:Label ID="LabelPrix" runat="server"></asp:Label></asp:Panel>
                        </asp:Panel>
                    </ContentTemplate>
                </asp:UpdatePanel>
                <asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False">
                     <ContentTemplate>
                        <asp:Panel ID="PanelPanier" runat="server" BackColor="Blue" CssClass="PlusADroite AligneMilieu" Height="450px"
                            Width="400px">
                            <asp:ImageButton ID="ImageButton1" runat="server" AlternateText="Panier" ImageUrl="~/images/panier.png" OnClick="ImageButton1_Click" />
                            <asp:Panel ID="PanelPanierConteneurPhoto" runat="server" Width="400px" Height="299px" ScrollBars="Auto">
                                <asp:UpdateProgress ID="UpdateProgressPanier" runat="server" DisplayAfter="100" DynamicLayout="true">
                                    <ProgressTemplate>
                                        <asp:Image ID="Image2" runat="server" ImageAlign="Middle" ImageUrl="~/images/ajax-loader-DDL.gif" />
                                        Mise à jour du panier...
                                    </ProgressTemplate>
                                </asp:UpdateProgress>
                            </asp:Panel>
                            <asp:ImageButton ID="ImageButtonValierLePanier" runat="server" OnClick="ImageButtonValierLePanier_Click" /></asp:Panel>
                     </ContentTemplate>
                </asp:UpdatePanel>
                <asp:UpdatePanel ID="UpdatePanel4" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="False">  
                    <ContentTemplate>
                        <asp:Panel ID="Panel5" CssClass="SousPanelFloat" runat="server" Height="120px" Width="1000px" BackColor="Green">
                            &nbsp;<asp:Panel ID="PanelPellicule" CssClass="PlusADroite AligneMilieu PanelPellicule" runat="server" Height="120px" Width="1000px" ScrollBars="Horizontal" HorizontalAlign="Center">
                            <asp:UpdateProgress ID="UpdateProgressPellicule" runat="server" DisplayAfter="100" DynamicLayout="true">
                                <ProgressTemplate>
                                    <asp:Image ID="ImageUpdateProgressPellicule" runat="server" ImageAlign="Middle" ImageUrl="~/images/ajax-loader-DDL.gif" />
                                    Mise à jour des miniatures...
                                </ProgressTemplate>
                            </asp:UpdateProgress>
                            </asp:Panel>
                            &nbsp;
                        </asp:Panel>  
                    </ContentTemplate>
                </asp:UpdatePanel>
            </div>
        </form>
    </body>
    </html>
    Voici le code-behind :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    using System;
    using System.IO;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Collections.Generic;
    using System.Reflection;
    using System.Xml;
    using System.Data.SqlClient;
     
    public partial class Visonneuse : System.Web.UI.Page
    {
        //private Guid InvoiceId;
        private Guid IdDeLaFenetre;
        private DataTable Commande;
        //Invoice Panier;
        protected void Page_Load(object sender, EventArgs e)
        {
     
                bool IsFirstTime = false;
                // A ne faire que lors du 1er chargement de la page
                if (!(Page.IsPostBack))
                {
                    IdDeLaFenetre = Guid.NewGuid();
                    ViewState["IdDeLaFenetre"] = IdDeLaFenetre.ToString();
                    ViewState.Add("LangueSelectionnee_" + IdDeLaFenetre, "fr");
                    IsFirstTime = true;
                }
                    else IdDeLaFenetre = new Guid(ViewState["IdDeLaFenetre"].ToString());
                    // On récupère la langue choisie
                    // On récupère le titre de la galerie
                    DataSet DataSetPhotosDeLaGalerie = new DataSet();
                    // Ouverture connexion BDD
                    SqlConnection Connexion = new SqlConnection(ConfigurationManager.AppSettings["ConnectionBase"]);
                    Connexion.Open();
     
                    // Si un dataset est déjà présent en variable de session, on le prend. Sinon on récupère les photos
                    if (Session["DataSetPhotos_" + IdDeLaFenetre.ToString()] == null)
                    {
                        SqlCommand Commande = new SqlCommand("aspnet_GetAllPhotosByPartialPath", Connexion);
                        Commande.CommandType = CommandType.StoredProcedure;
                        SqlDataAdapter Adapteur = new SqlDataAdapter(Commande);
                        SqlParameter Chemin = Commande.Parameters.Add("@PartialPath", SqlDbType.VarChar, 1000);
                        Chemin.Value = Path.GetDirectoryName(Request.AppRelativeCurrentExecutionFilePath).Replace("\\","/") + "%";
                        Adapteur.Fill(DataSetPhotosDeLaGalerie);
     
                        DataSet DataSetTitre = new DataSet();
                        Commande = new SqlCommand("aspnet_GetTitreName", Connexion);
                        Commande.CommandType = CommandType.StoredProcedure;
                        Adapteur = new SqlDataAdapter(Commande);
                        SqlParameter TitreId = Commande.Parameters.Add("@TitreId", SqlDbType.Int);
     
                        TitreId.Value = DataSetPhotosDeLaGalerie.Tables[0].Rows[0]["TitreId"];
                        Adapteur.Fill(DataSetTitre);
                        DataRow[] TitreName = DataSetTitre.Tables[0].Select("Langage='" + ViewState["LangueSelectionnee_" + IdDeLaFenetre] + "'".ToString());
                        LabelTitreGalerie.Text = TitreName[0]["TitreName"].ToString();
                        Session["DataSetPhotos_" + IdDeLaFenetre.ToString()] = DataSetPhotosDeLaGalerie;
                    }
                    else DataSetPhotosDeLaGalerie = (DataSet)Session["DataSetPhotos_" + IdDeLaFenetre.ToString()];
                    Connexion.Close();
     
                    // Création du conteneur des miniatures (nécessaire afin de correctement gérer l'overflow horizontal)
                    Panel Conteneur = new Panel();
                    Conteneur.Width = new Unit(120 * DataSetPhotosDeLaGalerie.Tables[0].Rows.Count/2);
                    foreach (DataRow Ligne in DataSetPhotosDeLaGalerie.Tables[0].Rows)
                    {
                        // On ne sélectionne qu' 1/2 photo puisqu'on a les francais ET les anglais dans le dataset
                        if (Ligne["Langage"].ToString() == ViewState["LangueSelectionnee_" + IdDeLaFenetre].ToString())
                        {
                          // lors du premier passage on sélectionne et affiche en grand la première photo de la galerie
                          if (IsFirstTime)
                          {
                              ViewState.Add("PhotoSelectionnee_" + IdDeLaFenetre.ToString(), Ligne["PhotoId"].ToString());
                              IsFirstTime = false;
                          }
                          // Création de la miniature et des évents associés
                          Conteneur.CssClass = "PlusADroite MarginLeftRight20px";
                          ImageButton Miniature = new ImageButton();
                          Miniature.ImageUrl = Ligne["PhotoVignettePath"].ToString();
                          Miniature.ImageAlign = ImageAlign.Middle;
                          Miniature.Command += new CommandEventHandler(Miniature_Command);
                          Miniature.CommandName = Ligne["PhotoVignettePath"].ToString();
                          Miniature.CommandArgument = Ligne["PhotoId"].ToString();
                          Miniature.CssClass = "Image";
                          Conteneur.Controls.Add(Miniature);
                        }
     
                }
                PanelPellicule.Controls.Add(Conteneur);
                MAJPanier();
        }
     
        /// <summary>
        /// Rafraichissement du panier
        /// </summary>
        private void MAJPanier()
        {
            if (Session["Panier_" + Request.UserHostAddress] != null)
            {
                // Récupération de la commande utilisateur
                PanelPanierConteneurPhoto.Controls.Clear();
                Commande = (DataTable)Session["Panier_" + Request.UserHostAddress];
                foreach (DataRow PhotoCommandee in Commande.Rows)
                {
                    AjoutImagePanier(PhotoCommandee["CheminVignette"].ToString(), PhotoCommandee["PhotoId"].ToString(), PhotoCommandee["PhotoName"].ToString(), PhotoCommandee["Prix"].ToString());
                }
                UpdatePanel3.Update();
                PanelPanierConteneurPhoto.Focus();
            }
        }
     
        /// <summary>
        /// CLick sur la miniature. Passage en paramètre de l'ID et du nom de la photo
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Miniature_Command(object sender, CommandEventArgs e)
        {
            IdDeLaFenetre = new Guid(ViewState["IdDeLaFenetre"].ToString());
            ViewState["PhotoSelectionnee_" + IdDeLaFenetre.ToString()] = e.CommandArgument.ToString();
            DataSet DataSetPhotosDeLaGalerie = (DataSet)Session["DataSetPhotos_" + IdDeLaFenetre.ToString()];
            DataRow[] LigneSelectionnee = DataSetPhotosDeLaGalerie.Tables[0].Select("PhotoId=" + e.CommandArgument.ToString() + "AND Langage='" + ViewState["LangueSelectionnee_" + IdDeLaFenetre].ToString() + "'");
            Label1.Text = LigneSelectionnee[0]["PhotoName"].ToString();
            LabelNom.Text = LigneSelectionnee[0]["PhotoPrice"].ToString() + " €";
            UpdatePanel1.Update();
        }
     
     
        /// <summary>
        /// Accesseur PhotoAAfficher (variable passée à la visionneuse flash)
        /// </summary>
        public string AccesseurPhotoAAfficher
        {
            get
            {
                IdDeLaFenetre = new Guid(ViewState["IdDeLaFenetre"].ToString());
                return ViewState["PhotoSelectionnee_" + IdDeLaFenetre.ToString()].ToString(); 
            }
            set {
                IdDeLaFenetre = new Guid(ViewState["IdDeLaFenetre"].ToString());
                ViewState["PhotoSelectionnee_" + IdDeLaFenetre.ToString()] = value; 
            }
        }
     
        /// <summary>
        /// Méthode qui ajoute un contrôle panier  dans le panel "Panier"
        /// </summary>
        protected void AjoutImagePanier(string CheminVignette, string PhotoId, string Nom, string Prix)
        {
            Control LienVisionneusePagePhoto = LoadControl("~/controles/ControlePanier.ascx", new object[] {});
     
            Image Vignette = (Image)LienVisionneusePagePhoto.FindControl("MiniatPhoto");
            Vignette.ImageUrl = CheminVignette;
            ImageButton Supprimer = (ImageButton)LienVisionneusePagePhoto.FindControl("BtnSupprimer");
     
            // Ajout de l'event SUPPRESSION (celui où il faut cliquer 2 fois distinctement pour effacer)
            Supprimer.Command += new CommandEventHandler(Supprimer_Command);
            Supprimer.CommandArgument = PhotoId;
            Supprimer.CommandName = PhotoId;
            Label LabelNom = (Label)LienVisionneusePagePhoto.FindControl("LabelNom");
            LabelNom.Text = Nom;
            Label LabelPrix = (Label)LienVisionneusePagePhoto.FindControl("LabelPrix");
            LabelPrix.Text = Prix;
     
            PanelPanierConteneurPhoto.Controls.Add(LienVisionneusePagePhoto);
        }
     
        /// <summary>
        /// Délégué de suppression. Passage en param du photoId
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Supprimer_Command(object sender, CommandEventArgs e)
        {
            Commande = (DataTable)Session["Panier_" + Request.UserHostAddress];
            DataRow[] LigneSelectionnee = Commande.Select("PhotoId=" + e.CommandArgument.ToString());
            Commande.Rows.Remove(LigneSelectionnee[0]);
            Session["Panier_" + Request.UserHostAddress] = Commande;
            MAJPanier();
        }
     
     
     
        /// <summary>
        /// Méthode lors du clic sur une miniature
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            IdDeLaFenetre = new Guid(ViewState["IdDeLaFenetre"].ToString());
            DataSet DataSetPhotosDeLaGalerie = (DataSet)Session["DataSetPhotos_" + IdDeLaFenetre.ToString()];
     
            if (Session["Panier_" + Request.UserHostAddress] != null)
            {
                Commande = (DataTable)Session["Panier_" + Request.UserHostAddress];
            }
            else
            {
                Commande = new DataTable("Commande");
                Commande.Columns.Add("PhotoId", Type.GetType("System.Int32"));
                Commande.Columns.Add("PhotoName", Type.GetType("System.String"));
                Commande.Columns.Add("CheminVignette", Type.GetType("System.String"));
                Commande.Columns.Add("Prix", Type.GetType("System.Decimal"));
            }
            DataRow[] LigneSelectionnee = DataSetPhotosDeLaGalerie.Tables[0].Select("PhotoId=" + Convert.ToInt16(ViewState["PhotoSelectionnee_" + IdDeLaFenetre.ToString()]) + "AND Langage='"+ ViewState["LangueSelectionnee_" + IdDeLaFenetre].ToString() + "'");
            DataRow LigneAjoutee = Commande.NewRow();
            LigneAjoutee["PhotoId"] = LigneSelectionnee[0]["PhotoId"];
            LigneAjoutee["PhotoName"] = LigneSelectionnee[0]["PhotoName"];
            LigneAjoutee["CheminVignette"] = LigneSelectionnee[0]["PhotoVignettePath"];
            LigneAjoutee["Prix"] = LigneSelectionnee[0]["PhotoPrice"];
            Commande.Rows.Add(LigneAjoutee);
            Session["Panier_" + Request.UserHostAddress] = Commande;
            foreach (DataRow PhotoCommandee in Commande.Rows)
            {
                AjoutImagePanier(PhotoCommandee["CheminVignette"].ToString(), PhotoCommandee["PhotoId"].ToString(), PhotoCommandee["PhotoName"].ToString(), PhotoCommandee["Prix"].ToString());
            }
            MAJPanier();
        }
     
        /// <summary>
        /// Chargement de contrôles utilisateur
        /// </summary>
        /// <param name="UserControlPath"></param>
        /// <param name="constructorParameters"></param>
        /// <returns></returns>
        public UserControl LoadControl(string UserControlPath, params object[] constructorParameters)
        {
            List<Type> constParamTypes = new List<Type>();
            foreach (object constParam in constructorParameters)
            {
                constParamTypes.Add(constParam.GetType());
            }
     
            UserControl ctl = Page.LoadControl(UserControlPath) as UserControl;
     
            // On recherche le constructeur approprié ...
            ConstructorInfo constructor = ctl.GetType().BaseType.GetConstructor(constParamTypes.ToArray());
     
            // Et on l'appelle
            if (constructor == null)
            {
                throw new MemberAccessException("Le constructeur n'existe pas : " + ctl.GetType().BaseType.ToString());
            }
            else
            {
                constructor.Invoke(ctl, constructorParameters);
            }
     
            // Et enfin, on retourne le controle
            return ctl;
        }
        /// <summary>
        /// Se produit lors de la validation du panier.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ImageButtonValierLePanier_Click(object sender, ImageClickEventArgs e)
        {
            if (Session["Panier_" + Request.UserHostAddress] != null)
            {
                Commande = (DataTable)Session["Panier_" + Request.UserHostAddress];
     
                if (Commun.AccesseurListeCommandes.Contains(Request.UserHostAddress))
                {
                    Commun.AccesseurListeCommandes[Request.UserHostAddress] = Commande;
                }
                else Commun.AccesseurListeCommandes.Add(Request.UserHostAddress, Commande);
                Response.Redirect("~/photos.aspx");
            }
        }
        /// <summary>
        /// Click sur le bouton changement langue
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ImageButtonFr_Click(object sender, ImageClickEventArgs e)
        {
             IdDeLaFenetre = new Guid(ViewState["IdDeLaFenetre"].ToString());
             if (ViewState["LangueSelectionnee_" + IdDeLaFenetre] != null)
             {
                 ViewState["LangueSelectionnee_" + IdDeLaFenetre] = "fr";
             }
             else ViewState.Add("LangueSelectionnee_" + IdDeLaFenetre, "fr");
        }
        protected void ImageButtonEn_Click(object sender, ImageClickEventArgs e)
        {
            IdDeLaFenetre = new Guid(ViewState["IdDeLaFenetre"].ToString());
            if (ViewState["LangueSelectionnee_" + IdDeLaFenetre] != null)
            {
                ViewState["LangueSelectionnee_" + IdDeLaFenetre] = "en";
            }
            else ViewState.Add("LangueSelectionnee_" + IdDeLaFenetre, "en");
        }
    }
    Et le code du user control "ControlPanier"

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="ControlePanier.ascx.cs" Inherits="controles_ControlePanier" %>
    <asp:Panel ID="PanelConteneur" runat="server" Style="clear: none; float: left; margin: 10px;" Width="270px">
        <asp:Image ID="MiniatPhoto" runat="server" style="clear: none; float: left" />
        <asp:Panel ID="Panel1" runat="server" Height="50px" Style="clear: none; float: left" Width="130px" HorizontalAlign="Center">
            <asp:Label ID="LabelNom" runat="server" Text="Label"></asp:Label><br />
            <asp:Label ID="LabelPrix" runat="server" Text="Label"></asp:Label></asp:Panel>
        <asp:Panel ID="Panel2" runat="server" Height="50px" Style="clear: right; float: right" Width="40px">
            <asp:ImageButton ID="BtnSupprimer" runat="server" ImageUrl="~/images/Supprimer.png" ImageAlign="Middle" />
        </asp:Panel>
    </asp:Panel>
    J'espère être assez clair et pas trop long. N'hésitez pas à me demander plus d'informations si vous le jugez nécessaire.

    Merci pour ceux qui prendront le temps de regarder !!!

    Cordialement,

    Nixar

  2. #2
    Membre Expert Avatar de Arthis
    Profil pro
    Inscrit en
    Octobre 2003
    Messages
    1 265
    Détails du profil
    Informations personnelles :
    Âge : 48
    Localisation : Italie

    Informations forums :
    Inscription : Octobre 2003
    Messages : 1 265
    Par défaut
    probleme de cycle de vie de ta page surement , essaie de creer tes objets dans le oninit de ta page, c'est de toute manière plus propre.

  3. #3
    Membre chevronné
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2004
    Messages
    417
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Finance

    Informations forums :
    Inscription : Novembre 2004
    Messages : 417
    Par défaut
    Tout à fait Arthis.

    Plus exactement ton probléme vient du fait que tu ajoute ton UserControl(ControlePanier.ascx) dans un autre evenement (beaucoup trop tard).

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
        protected void AjoutImagePanier(string CheminVignette, string PhotoId, string Nom, string Prix)
        {
          ...
     
            PanelPanierConteneurPhoto.Controls.Add(LienVisionneusePagePhoto);
        }
    Joue plutot avec visible si tu peux

  4. #4
    Membre éclairé Avatar de Nixar
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    302
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 302
    Par défaut
    Merci de vos réponses à tous les 2.
    Du coup j'ai besoin de précisions...
    @Arthis :
    Concernant la déclaration dans le OnInit, il faut faire un truc comme ça? :

    protected override void OnInit(EventArgs e)
    {
    //Mes déclarations de variables
    Base.OnInit(e);
    }

    @Gyzmau :

    Tu veux dire qu'il faut que j'ajoute autant de contrôles qu'il y a d'images dès le chargement de la page avec visible=false, et qu'en fonction du choix de l'utilisateur, je change la valeur de visible?

    Merci de vos éclaircissements.

    Nixar

  5. #5
    Membre chevronné
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2004
    Messages
    417
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Finance

    Informations forums :
    Inscription : Novembre 2004
    Messages : 417
    Par défaut
    je dirais qu'il faut reflechir plus au systéme du style tu en prépare tjs un d'avance au cas ou.
    Attention je sais pas si ca marche mais ca devrais.
    tu vois ce que je veux dire?


    <HS>
    ps: un peu comme chrome qui prepare tjs un process d'avance au cas ou tu ouvre un nouveau tab.
    </HS>

    Mais tu peux aussi la faire plus bourrin et charger autant de control que t'as d'image. Mais bon..

    edit:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    protected override void OnInit(EventArgs e)
    {
    //tes ajouts de controls
    Base.OnInit(e);
    }

  6. #6
    Membre éclairé Avatar de Nixar
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    302
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 302
    Par défaut
    Je ne suis pas sûr de voir : je viens de faire un essai et d'après ce que je vois toutes les variables de session et le viewstate ne semblent pas accessibles dans le OnInit().

    Comment accéder à ces variables depuis le OnInit()?

    Ce que je ne comprends pas non plus, c'est le coup d'avoir toujours un contrôle d'avance... Si tu le temps pour un exemple, je suis preneur

    Merci bien en tout cas !!

Discussions similaires

  1. problème d'ajout et suppression de programmes
    Par ran_hery dans le forum Windows XP
    Réponses: 2
    Dernier message: 14/12/2005, 12h21
  2. [ECLIPSE WT] Problème d'ajout du serveur Tomcat
    Par SEMPERE Benjamin dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 12/12/2005, 12h20
  3. Problème d'ajout de mois
    Par auriolbeach dans le forum Access
    Réponses: 5
    Dernier message: 02/10/2005, 22h22
  4. Problème d'ajout d'imprimante sur LPT1
    Par arnaud_verlaine dans le forum Périphériques
    Réponses: 10
    Dernier message: 15/03/2005, 22h23
  5. Problème d'ajout multiples dans un BDD Access
    Par arnaud_verlaine dans le forum Langage SQL
    Réponses: 3
    Dernier message: 31/05/2004, 13h34

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo