Bonjour à tous,
Je suis occupé à faire une page qui contient une zone répétée pour afficher le contenu d'une liste avec un formulaire en dessous pour mettre à jour les informations.
Pour limiter les refresh, j'ai utilisé des updatePanel comme suit:
Page ASPX:
Et dans le code-behind, j'ai ceci:
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 <asp:UpdatePanel ID="upContentList" runat="server"> <ContentTemplate> <asp:Repeater ID="rptContentList" runat="server"> <HeaderTemplate> <table> <tr> <th>Identifiant</th> <th>Nom du groupe</th> <th>Description</th> <th>Niveau d'accès</th> <th>Actions</th> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td><%# Container.DataItem("IdGroup")%></td> <td><%# Container.DataItem("InternalName")%></td> <td><%# Container.DataItem("Description")%></td> <td><%# Container.DataItem("IdLevel")%></td> <td> <asp:ImageButton ID="iBtnEditGroup" runat="server" CommandName="EditGroup" CommandArgument='<%# Container.DataItem("IdGroup")%>' ImageUrl='../images/backend/edit.png' AlternateText="Modifier" /> <asp:ImageButton ID="iBtnDeleteGroup" runat="server" CommandName="DeleteGroup" CommandArgument='<%# Container.DataItem("IdGroup")%>' ImageUrl='../images/backend/trash.png' AlternateText="Supprimer" /> </td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> </ContentTemplate> </asp:UpdatePanel> </div> <asp:UpdatePanel ID="upContentEdit" runat="server"> <ContentTemplate> <div class="ContentEditing"> <asp:Label ID="lblDebug" runat="server" Text="Debug"></asp:Label><br /> <asp:Label ID="lblIdGroup" runat="server" Text="Identifiant :" AssociatedControlID="txtIdGroup"></asp:Label><asp:TextBox ID="txtIdGroup" runat="server" Enabled="False" Width="25px"></asp:TextBox><br /> <asp:Label ID="lblGroupName" runat="server" Text="Nom du groupe :" AssociatedControlID="txtGroupName"></asp:Label><asp:TextBox ID="txtGroupName" runat="server" MaxLength="50"></asp:TextBox><br /> <asp:Label ID="lblDescription" runat="server" Text="Description :" AssociatedControlID="txtDescription"></asp:Label><asp:TextBox ID="txtDescription" runat="server" MaxLength="250" Width="250px"></asp:TextBox><br /> <asp:Label ID="lblAccessLevel" runat="server" Text="Niveau d'accès :" AssociatedControlID="txtAccessLevel"></asp:Label><asp:TextBox ID="txtAccessLevel" runat="server" Width="25px"></asp:TextBox><br /> <div> <asp:Button ID="btnSave" runat="server" Text="Enregistrer" /><asp:Button ID="btnCancel" runat="server" Text="Annuler" /> </div> </div> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="rptContentList" EventName="ItemCommand" /> <asp:AsyncPostBackTrigger ControlID="btnCancel" EventName="Click" /> <asp:AsyncPostBackTrigger ControlID="btnSave" EventName="Click" /> </Triggers> </asp:UpdatePanel> <script type="text/javascript"> $('input[id*="iBtnDeleteGroup"]').click(function () { return confirm("Etes-vous sûr de vouloir supprimer ce groupe ?\n\n/!\\ Cette action est irréversible /!\\"); }); </script>
Si je clique sur un des ImageButton pour la première fois, le postback se fait correctement, mais on ne passe pas dans le code "rptContentList_ItemCommand". Au deuxième clic, le traitement est effectué correctement.
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 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then Dim dsGroupList As DataSet = oDa.GroupList() rptContentList.DataSource = dsGroupList rptContentList.DataBind() End If End Sub Protected Sub rptContentList_ItemCommand(source As Object, e As RepeaterCommandEventArgs) Handles rptContentList.ItemCommand Select Case e.CommandName Case "EditGroup" Dim dsGroupDetail As DataSet = oDa.GroupDetail(CInt(e.CommandArgument)) txtIdGroup.Text = dsGroupDetail.Tables(0).Rows(0).Item("IdGroup") txtGroupName.Text = dsGroupDetail.Tables(0).Rows(0).Item("InternalName") txtDescription.Text = dsGroupDetail.Tables(0).Rows(0).Item("Description") txtAccessLevel.Text = dsGroupDetail.Tables(0).Rows(0).Item("IdLevel") Case "DeleteGroup" End Select End Sub
Si je retire "If Not Page.IsPostBack Then" dans le Page_Load, chaque clic exécute bien "rptContentList_ItemCommand", mais les données qui me sont retournées ne sont pas bonnes.
Merci d'avance pour votre aide.
jérôme
Partager