Bonjour,

Un gros problème c'est apparu lors du dévellopement de mon applic.

J'utilise deux listbox, une contenant des utilisateurs (L1) et une autre vide (L2).

A l'aide de javascript je fais véhiculer les utilisateurs d'une listbox a l'autre grace a un bouton.

Le problème est que je n'arrive pas a récupérer le contenu de ma listbox (L2) dans le code-behind, le nombre d'élément vaut toujours 0.

je n'utilise pas de postback ni d'ajax.

Comment faire ?

Utiliser Ajax et effectuer un postback ?


Merci d'avance.


Code Javascript


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
            function Deplacer(l1,l2) {
 
		        if (l1.options.selectedIndex>=0) {
			        o=new Option(l1.options[l1.options.selectedIndex].text,l1.options[l1.options.selectedIndex].value);
			        l2.options[l2.options.length]=o;
			        l1.options[l1.options.selectedIndex]=null;
		        }
		        else{
			        alert("Aucun élément sélectionné");
		        }
		    }

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
 <table>
 
            <tr>
            <td>
                <asp:ListBox ID="ListBox1" runat="server" Width="200px">
                </asp:ListBox>
                <cc1:ListSearchExtender ID="ListSearchExtender1" runat="server" TargetControlID="ListBox1">
                </cc1:ListSearchExtender>
            </td>
 
            <td> 
                <center>
                    <input id="Button4" type="button" value="Ajouter >>>" onclick="Deplacer(this.form.ctl00_Corps_ListBox1,this.form.ctl00_Corps_ListBox2)" />
                    <br /><br />
                    <input id="Button3" type="button" value="<<< Enlever" onclick="Deplacer(this.form.ctl00_Corps_ListBox2,this.form.ctl00_Corps_ListBox1)" />
                </center>
            </td>
 
            <td>
                <asp:ListBox ID="ListBox2" runat="server" Width="200px">
                </asp:ListBox>
            </td>
 
            </tr>
        </table>
 
 
 
 
    protected void liste_formateur()
    {
        query = "SELECT * FROM vue_formateur WHERE ind_activer=1";
        SqlConnection cnx = (SqlConnection)Session["oConnection"];
 
        try
        {
 
            SqlCommand myCommand = new SqlCommand(query, cnx);
            reader = myCommand.ExecuteReader();
 
            while (reader.Read())
            {
                ListItem item = new ListItem(reader["ind_nom"].ToString()+" "+reader["ind_prenom"].ToString(),reader["ind_code"].ToString());
                ListBox1.Items.Add(item);
            }
 
        }
        catch (System.Exception ex)
        {
            Console.WriteLine(ex.Message.ToString());
        }
        finally
        {
            reader.Close();
        }
    }