J'ai un UserControl qui est utilisé dans un UpdatePanel. UserControl est un formulaire assez simple qui apparaît via un ModalPopupExtender (qui fait également partie de UserControl). Il y a quatre DropDownLists, ainsi que d'autres éléments de l'interface utilisateur. Trois des quatre DropDownLists ont AutoPostBack = "true", avec des événements SelectedIndexChanged qui se déclenchent sur le serveur et provoquent la reliaison de certaines des autres DropDownLists.DropDownList dans ModalPopup/UpdatePanel ne se déclenche pas par intermittence SelectedIndexChanged
Deux des trois DDL que AutoPostBack fonctionnent correctement. L'un d'eux, que je viens d'ajouter, montre un comportement étrange. Supposons que je lie cinq éléments: 1, 2, 3, 4, 5. Je mets l'objet SelectedIndex à 0, ce qui fait 1 l'élément sélectionné.
Si je sélectionne 5 puis 1 et continue de basculer d'avant en arrière, tout fonctionne correctement. La publication se produit et SelectedIndexChanged se déclenche. À chaque fois.
Si jamais je sélectionne 2 ou 4, la publication se produit mais SelectedIndexChanged ne se déclenche pas. À chaque fois. Si jamais je sélectionne 3, quelque chose de bizarre se produit et parfois la valeur du DDL revient à 1. Même si les points d'arrêt semblent montrer qu'il ne se reconnecte pas et qu'aucun code inattendu n'est en cours d'exécution. Je sais que votre premier instinct sera probablement que je me trompe sur le fait que le code de relindication ne fonctionne pas, mais j'ai littéralement regardé le débogueur pendant des heures en essayant de trouver mon erreur. Beaucoup de points d'arrêt. Je ne comprends pas - ce n'est vraiment pas si compliqué.
Mais évidemment, il me manque quelque chose.
J'ai mis environ quatre heures dans ce domaine jusqu'à présent et je pense que je ne fais que moudre à ce stade. Je pourrais utiliser une autre perspective.
HTML (et par la manière, DropProtocolCycleID est le contrôle du problème):
<asp:Panel ID="PanelPopupAssign" runat="server" Style="display:none; cursor: move; width:325px; background-color:Transparent;">
<BlueUI:Panel runat="server" ID="PanelPatientProtocol" Width="500px" HeaderText="Assign Protocol">
<table cellspacing="5">
<tr>
<td style="width:150px;"></td>
<td style="width:50px;"></td>
<td style="width:125px;"></td>
</tr>
<tr runat="server" id="TableRowCategory">
<td align="right">Category:</td>
<td colspan="2">
<asp:DropDownList runat="server" ID="DropProtocolCategories" CausesValidation="false" autopostback="true"/>
</td>
</tr>
<tr>
<td align="right">Protocol:</td>
<td colspan="2">
<asp:DropDownList ID="DropProtocolID" runat="server" Enabled="false" CausesValidation="false" autopostback="true"/>
<asp:Label ID="LabelProtocolName_SetDate" runat="server" />
</td>
</tr>
<tr>
<td colspan="3">
<table style="margin-left: 120px">
<tr>
<td align="right">Cycle:</td>
<td><asp:DropDownList ID="DropProtocolCycleID" runat="server" autopostback="true" /></td>
</tr>
<tr>
<td align="right">Day:</td>
<td>
<asp:DropDownList ID="DropProtocolCycleDayID" runat="server" Enabled="false" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="right">Start Date:</td>
<td colspan="2">
<table>
<tr>
<td>
<asp:Textbox ID="TextProtocolStartDate" runat="server" Width="65px"
BackColor="Transparent" BorderStyle="None" ReadOnly="True" Font-Size="11px"
ForeColor="#1C4071" Font-Names="Verdana" ValidationGroup="AssignProtocol" />
</td>
<td>
<img id="ImageProtocolStartDate"
alt="Calendar"
onclick="CalProtocolStartDate.show();"
class="calendar_button"
src="../../Images/Icons/btn_calendar.gif"
width="25"
height="22" />
<asp:RequiredFieldValidator ID="ValRequiredProtocolStartDate" runat="server" display="Dynamic"
ControlToValidate="TextProtocolStartDate" ErrorMessage="Protocol Start Date is required!"
InitialValue="(None)"
Enabled="false" ValidationGroup="AssignProtocol">*</asp:RequiredFieldValidator>
</td>
</tr>
</table>
</td>
</tr>
</table>
<ComponentArt:Calendar runat="server"
id="CalProtocolStartDate"
AllowMonthSelection="false"
AllowMultipleSelection="false"
AllowWeekSelection="false"
CalendarCssClass="calendar"
TitleCssClass="title"
ControlType="Calendar"
DayCssClass="day"
DayHeaderCssClass="dayheader"
DayHoverCssClass="dayhover"
DayNameFormat="FirstTwoLetters"
ImagesBaseUrl="~/Images/Calendar/"
MonthCssClass="month"
NextImageUrl="cal_nextMonth.gif"
NextPrevCssClass="nextprev"
OtherMonthDayCssClass="othermonthday"
PopUp="Custom"
PopUpExpandControlId="ImageProtocolStartDate"
PrevImageUrl="cal_prevMonth.gif"
SelectedDate=""
VisibleDate=""
SelectedDayCssClass="selectedday"
SelectMonthCssClass="selector"
SelectMonthText="¤"
SelectWeekCssClass="selector"
SelectWeekText="»"
SwapDuration="300"
SwapSlide="Linear"
AutoPostBackOnSelectionChanged="False"
PopUpCollapseDuration="0"
ClientSideOnSelectionChanged="onCalProtocolStartDateChange">
<ClientEvents>
<Load EventHandler="Calendar1_onLoad" />
</ClientEvents>
</ComponentArt:Calendar>
<br />
<div style="text-align:center;">
<asp:Button ID="ButtonSaveProtocol" runat="server" Text="Save" ValidationGroup="AssignProtocol" Enabled="false" />
<asp:Button ID="ButtonCancel" runat="server" Text="Cancel" CausesValidation="false" />
</div>
<br />
</BlueUI:Panel>
</asp:Panel>
<ajaxToolkit:ModalPopupExtender id="ModalPopupExtenderAssignProtocol" runat="server"
popupcontrolid="PanelPopupAssign" popupdraghandlecontrolid="PanelPopupAssign" CancelControlID="ButtonCancel"
targetcontrolid="ButtonAssignProtocol" BackgroundCssClass="modalBackground" RepositionMode="RepositionOnWindowResizeAndScroll" >
</ajaxToolkit:ModalPopupExtender>
codebehind pertinente:
Private Sub DropProtocolCycleID_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropProtocolCycleID.SelectedIndexChanged
Me.Show()
Me.SetupDropProtocolCycleDayID()
End Sub
Public Sub Show()
Me.ModalPopupExtenderAssignProtocol.Show()
End Sub
Voici le code où je lie DropProtocolCycleID, si vous êtes intéressé . Il tire en cas SelectedIndexChanged de DropProtocolID qui fonctionne réellement fiable:
Private Sub SetupDropProtocolCycleID()
If Me.DropProtocolID.SelectedValue = Constants.NothingSelected Then
Me.DropProtocolCycleID.Enabled = False
Exit Sub
Else
Me.DropProtocolCycleID.Enabled = True
End If
Dim ProtocolID As Integer = Me.DropProtocolID.SelectedValue
Dim ProtocolCycles As DataTable = ProtocolManager.GenerateCycleTable(ProtocolID)
Me.DropProtocolCycleID.DataSource = ProtocolCycles
Me.DropProtocolCycleID.DataTextField = "ProtocolCycleNumber"
Me.DropProtocolCycleID.DataValueField = "ProtocolCycleID"
Me.DropProtocolCycleID.DataBind()
If DropProtocolCycleID.Items.Count > 0 Then
Me.DropProtocolCycleID.SelectedIndex = 0
End If
End Sub
ProtocolCycleNumber et ProtocolCycleID ne sont que des entiers. Aucune chance de quoi que ce soit qui pourrait interférer avec le javascript.
solution juste ... Bien sûr, il serait beaucoup mieux si « SelectedIndexChanged » juste travaillé :) – anthares