Bonjour,
j'ai créé un panel dans lequel j'ajoute des champs de formulaire dynamiquement.
Lors du chargement du panel, la méthode LoadChampFormExistant est appelé pour construire des champs input.
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 <asp:Panel ID="PanelChampForm" CssClass="DivPopUp2" Width="500px" runat="server" Visible="false"> <asp:ImageButton ID="ImageCloseChampForm" ImageUrl="~/img/x.gif" runat="server" Style="float: right;" OnClick="ImageCloseChampForm_Click" /> <asp:Label ID="lblTitreChampForm" runat="server" Style="font-size: 15px; font-weight: 900; color: #FF9A00; padding-left:160px;" Text="Gestion Champs Formulaire"></asp:Label> <br class="clear" /> <asp:LinkButton ID="linkAddChamp" runat="server" OnClick="AddChamp_Click" Style="text-decoration: none; color: #000; padding-left:190px;">Ajouter un champ : <asp:Image runat="server" ID="imgAddChamp" ImageUrl="~/img/+_bb.gif" /> </asp:LinkButton> <br /> <asp:HiddenField ID="hiddenNbChamps" runat="server" /> <div id="divChampsAjoutes" style="padding-left:200px;" runat="server"> </div> <br /> <asp:ImageButton ID="imgbValiderChampForm" ImageUrl="~/img/Valider_bb.jpg" runat="server" style="padding-left:220px;" OnClick="ValiderChampForm_Click" /> </asp:Panel>
Ensuite, lorsque j'appuie sur le bouton pour ajouter un champ, la méthode AddChamp_Click est appelée.
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 protected void LoadChampFormExistant() { int champs_count = 0; //on ajoute les input si ChampsFormulaire != "" if (tbChampsFormulaire.Text != "") { //on parse les differents champs string[] listChamps = tbChampsFormulaire.Text.Split(';'); foreach (string elt in listChamps) { champs_count++; //on creer les input divChampsAjoutes.InnerHtml += "<br/><input type=\"text\" name=\"tbChampAdd_" + champs_count + "\" value=\"" + elt + "\" class=\"champs\"/><br/>"; } } if (champs_count > 0) imgbValiderChampForm.Visible = true; hiddenNbChamps.Value = champs_count.ToString(); }
Lors de l'appui sur ajouter, un input est ajouté au panel, je le remplis.
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 protected void AddChamp_Click(object sender, EventArgs e) { int champs_count = Convert.ToInt32(hiddenNbChamps.Value); champs_count++; divChampsAjoutes.InnerHtml += "<br/><input type=\"text\" name=\"tbChampAdd_" + champs_count + "\" class=\"champs\" /><br/>"; hiddenNbChamps.Value = champs_count.ToString(); imgbValiderChampForm.Visible = true; }
Lors du second appui, un second input est créé mais la valeur que j'avais saisie dans le premier à disparue.
Ma question, comment sauvegarder les valeurs des inputs à chaque appui sur ajouter.
J'espère que mes explications sont claires.
Merci d'avance.
Partager