Salut,

Pour ceux qui suivent mes péripéties, j'ai créé une contrôle personnalisé permettant d'afficher une liste de boutons radio dans une liste HTML non ordonnée. Le contrôle hérite de System.Web.UI.WebControls.RadioButtonList. J'ai juste modifié la méthode Render() pour obtenir un rendu adéquat.
Je souhaite utiliser les évènements de ce contrôle, malheureusement ça ne fonctionne pas. Rien ne se passe lorsque je clique sur un des boutons radio du contrôle personnalisé.

Voici de quoi tester : contrôle personnalisé
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
Imports System.Text
Imports System.Web.UI.WebControls
 
Namespace Controls
    Public Class RadioButtonList
        Inherits System.Web.UI.WebControls.RadioButtonList
 
        Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
            Dim li As String = "<li id=""{0}"">{1}</li>"
            Dim radio As String = "<input id=""{0}"" name=""{1}"" type=""radio"" value=""{2}""{3}/>"
            Dim label As String = "<label for=""{0}"">{1}</label>"
            Dim classeCSS As String = ""
 
            If Not CssClass.Equals("") Then
                classeCSS = " class=""" & CssClass.ToString & """"
            End If
 
 
            Controls.Clear()
            writer.Indent = writer.Indent + 1
            writer.WriteLine("<ul " & _
                                "id=""" & ClientID & """" & _
                                 classeCSS & ">" _
                            )
 
            For i As Integer = 0 To Items.Count - 1
                Dim sLi As StringBuilder = New StringBuilder
                Dim sRadio As StringBuilder = New StringBuilder
                Dim sLabel As StringBuilder = New StringBuilder
 
                sRadio.AppendFormat( _
                    radio, _
                    ClientID & "_" & i.ToString, _
                    UniqueID, _
                    Items(i).Value, _
                    (IIf(Items(i).Selected, " checked=""checked"" ", "")) _
                )
 
                sLabel.AppendFormat( _
                    label, _
                    ClientID & "_" & i.ToString, _
                    Items(i).Text _
                )
 
                sLi.AppendFormat( _
                    li, _
                    "li" & ClientID & i.ToString, _
                    sRadio.ToString & sLabel.ToString _
                )
                writer.Indent = writer.Indent + 1
                writer.WriteLine(sLi.ToString())
                writer.Indent = writer.Indent - 1
            Next
 
            writer.WriteLine("</ul>")
            writer.Indent = writer.Indent - 1
        End Sub
 
    End Class
End Namespace
page aspx
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
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="radioButtonList.aspx.vb" Inherits="ControleSurcharge_radioButtonList" %>
<%@ Register Assembly="Bibliotheque" Namespace="Bibliotheque.Controls" TagPrefix="cc" %>
 
<!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">
    <title>Page sans titre</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
      <asp:RadioButtonList ID="RadioButtonList1" AutoPostBack="true" runat="server">
         <asp:ListItem Value="0" Text="0"></asp:ListItem>
         <asp:ListItem Value="1" Text="1"></asp:ListItem>
         <asp:ListItem Value="2" Text="2"></asp:ListItem>
      </asp:RadioButtonList>
      <cc:RadioButtonList ID="RadioButtonList2" AutoPostBack="true" runat="server"<%-- OnSelectedIndexChanged="RadioButtonList2_SelectedIndexChanged"--%>>
         <asp:ListItem Value="0" Text="0"></asp:ListItem>
         <asp:ListItem Value="1" Text="1"></asp:ListItem>
         <asp:ListItem Value="2" Text="2"></asp:ListItem>
      </cc:RadioButtonList>
      <asp:Label ID="Label1" runat="server" Text="Pas de sélection"></asp:Label>
    </div>
    </form>
</body>
</html>
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
Partial Class ControleSurcharge_radioButtonList
    Inherits System.Web.UI.Page
    'Dim RadioButtonList2 As ImmoMatchBibliotheque.Controls.RadioButtonList
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'AddHandler RadioButtonList2.SelectedIndexChanged, AddressOf RadioButtonList2_SelectedIndexChanged
    End Sub
    Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButtonList1.SelectedIndexChanged
        Label1.Text = sender.selectedvalue.ToString
    End Sub
    Protected Sub RadioButtonList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButtonList2.SelectedIndexChanged
        Label1.Text = sender.selectedvalue.ToString
    End Sub
End Class
J'ai essayé en spécifiant l'attribut OnSelectedIndexChanged, puis avec et sans un AddHandler, mais ça ne change rien. J'obtiens un message d'erreur lorsque j'essaie de déclarer mon objet avec WithEvents :
BC30260: 'RadioButtonList2' est déjà déclaré en tant que 'Protected Dim WithEvents RadioButtonList2 As Bibliotheque.Controls.RadioButtonList' dans ce class.
Voyez-vous d'où ça peut venir?

Merci par avance.