I'm in Asp.net 3.5 (Visual Studio 2008, VB). In a DetailsView, I've got several controls that need to perform hide/display actions, and I'm using an Update Panel. The first control is a radio button ("rblAttemptType") with two options: Phone Call or Letter. If the user chooses Phone Call, a textbox to record the time of the call opens (there's also a textbox to record the date, but it applies to both calls and letters, so it stays visible). Choosing Phone Call also enables/disenables another radio button ("rblSuccess") that records whether the contact attempt was successful. The options for rblSuccess are N/A, No and Yes. The N/A option applies when the user chooses Letter from rblAttemptType, in which case rblSuccess is also disabled (and more fields in the DetailsView become visible).
But if the user chooses Phone Call from rblAttemptType, rblSuccess is selection-cleared and enabled. Choosing no on rblSuccess reveals a drop-down list containing explanatory options (no answer, left voicemail etc.). One of the options is Other, which is supposed to reveal a textbox to record details.
Everything works, right up until that last step. It goes like this: I choose Phone Call, and the Time textbox appears. I type in the date and the time, then select No on rblSuccess, and the drop-down list appears. But when I make a selection on the drop-down list, nothing happens; i.e. the SelectedIndexChanged event assigned to the control isn't firing. And yes, it's set to AutoPostBack="True."
So--again--the SelectedIndexChanged subs for both of the radio buttons are working fine, but the one for the drop-down list isn't being hit.
Here's the code. I'm only including the parts of the DetailsView pertinent to this issue; let me know if you want the whole thing).
From the aspx page:
<asp:DetailsView ID="dvAppointment" runat="server" AutoGenerateRows="False" DataKeyNames="aID"
Visible="False" Caption="Appointment Details" BorderColor="#189AA1" BorderStyle="Solid"
BorderWidth="1px">
<RowStyle BackColor="White" BorderStyle="None" Font-Names="Verdana,Arial,Helvetica"
Font-Size="11px" Font-Strikeout="False" />
<FieldHeaderStyle BackColor="#449c77" CssClass="white" Font-Bold="True" Width="15%"
BorderColor="#189AA1" BorderStyle="Solid" BorderWidth="1px" />
<Fields>
<asp:BoundField DataField="aID" HeaderText="aID" Visible="False" ReadOnly="True" />
<asp:TemplateField HeaderText="Attempt Type" SortExpression="AttemptType" HeaderStyle-VerticalAlign="Middle">
<ItemTemplate>
<asp:Label ID="lblAttemptType" runat="server" Text='<%# Eval("AttemptTypeDetails") %>'></asp:Label>
<br />
<asp:Label ID="lblAttemptMessage" runat="server" Text='<%# ContactAttemptMessage()%>'
HtmlEncode="False" CssClass="FireBrick9" HtmlEncodeFormatString="False" />
</ItemTemplate>
<InsertItemTemplate>
<asp:Label ID="lblAttemptMessage" runat="server" Text='<%# ContactAttemptMessage()%>'
HtmlEncode="False" CssClass="FireBrick9" HtmlEncodeFormatString="False" />
<asp:RadioButtonList ID="rblAttemptType" runat="server" RepeatDirection="Horizontal"
AutoPostBack="true" OnSelectedIndexChanged="rblAttemptTypeChanged" CssClass="Text9B">
<asp:ListItem Value="1">Phone call</asp:ListItem>
<asp:ListItem Value="2">Letter</asp:ListItem>
</asp:RadioButtonList>
</InsertItemTemplate>
<HeaderStyle VerticalAlign="Middle"></HeaderStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Attempt Date" SortExpression="AttemptDate">
<ItemTemplate>
<asp:Label ID="lblAttemptDateWithTime" runat="server" Text='<%# AttemptDateDetails() %>'></asp:Label>
</ItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="txAttemptDate" runat="server" AutoCompleteType="Disabled" AutoPostBack="False"></asp:TextBox>
<asp:CalendarExtender ID="CalendarExtenderAttemptDate" runat="server" TodaysDateFormat="mm/dd/yyyy"
TargetControlID="txAttemptDate">
</asp:CalendarExtender>
<asp:UpdatePanel ID="UpdatePanelforAttempt" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="AttemptTimeLabel" runat="server" Text="Time of phone attempt (hh:mm AM/PM): "
Visible="False"></asp:Label>
<asp:TextBox ID="txAttemptTime" runat="server" ToolTip="Time should be in format XX:XX AM/PM"
Visible="False"></asp:TextBox>
<asp:MaskedEditExtender ID="txAttemptTimeTime_MaskedEditExtender" runat="server"
CultureAMPMPlaceholder="" CultureCurrencySymbolPlaceholder="" CultureDateFormat=""
CultureDatePlaceholder="" CultureDecimalPlaceholder="" CultureThousandsPlaceholder=""
CultureTimePlaceholder="" Enabled="True" TargetControlID="txAttemptTime" Mask="99:99 LL"
ClearMaskOnLostFocus="False" MaskType="Number">
</asp:MaskedEditExtender>
<asp:Label ID="LabelSuccess" runat="server" Text="<br /><br />Was the attempt successful?"
CssClass="Text8B" ></asp:Label>
<asp:RadioButtonList ID="rblSuccess" runat="server" OnSelectedIndexChanged="rblSuccessChanged"
RepeatDirection="Horizontal" AutoPostBack="True"
Enabled='<%# IIF(Eval("AttemptType")=1,"true","false") %>'>
<asp:ListItem Value="2">Yes</asp:ListItem>
<asp:ListItem Value="1">No</asp:ListItem>
<asp:ListItem Value="0" Selected="True">N/A</asp:ListItem>
</asp:RadioButtonList>
<asp:Label ID="lblNoContactReason" runat="server" Text="<br />Please clarify the contact attempt result:"
Visible="False" CssClass="smTextItalic"></asp:Label>
<asp:DropDownList ID="ddlrncType" runat="server" DataSourceID="sdsrncTypes" DataValueField="rncTypeID"
DataTextField="rncType" Visible="false" AutoPostBack="True" OnSelectedIndexChanged="ddlrncTypeChanged">
</asp:DropDownList>
<asp:Label ID="lblSpecify" runat="server" Text="<br /><br />Please Explain:<br />"
CssClass="smTextbold" Visible="False"></asp:Label>
<asp:TextBox ID="txrncOther" runat="server" Visible="false" ToolTip="Specific result (350 characters allowed)"
TextMode="MultiLine" CssClass="MultiLineInsert" Width="35%" />
</ContentTemplate>
</asp:UpdatePanel>
</InsertItemTemplate>
</asp:TemplateField>
</Fields>
<HeaderStyle BackColor="#449C77" BorderColor="#189AA1" BorderStyle="Solid" BorderWidth="1px" />
<InsertRowStyle Width="80%" BackColor="White" Font-Names="Verdana,Ariel,Helvetica"
Font-Size="11px" />
<EditRowStyle Width="77%" BackColor="White" Font-Names="Verdana,Ariel,Helvetica"
Font-Size="11px" />
<AlternatingRowStyle BackColor="#CFCFCF" Font-Names="Verdana,Ariel,Helvetica" Font-Size="11px" />
</asp:DetailsView>
From the VB code:
Protected Sub rblAttemptTypeChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim iAttemptTimeLabel As Label = DirectCast(dvAppointment.FindControl("AttemptTimeLabel"), Label)
Dim itxAttemptTime As TextBox = DirectCast(dvAppointment.FindControl("txAttemptTime"), TextBox)
Dim irblSuccess As RadioButtonList = DirectCast(dvAppointment.FindControl("rblSuccess"), RadioButtonList)
Dim iUpdatePanelforAttempt As UpdatePanel = DirectCast(dvAppointment.FindControl("UpdatePanelforAttempt"), UpdatePanel)
Dim AttemptType As Integer = 0
If Not sender.selectedValue = String.Empty Then
AttemptType = CInt(sender.selectedValue)
ViewState("AttemptType") = CInt(sender.selectedValue)
If AttemptType = 1 Then 'Phone
If Not iAttemptTimeLabel Is Nothing Then
iAttemptTimeLabel.Visible = True
End If
If Not itxAttemptTime Is Nothing Then
itxAttemptTime.Visible = True
End If
If Not irblSuccess Is Nothing Then
irblSuccess.Enabled = True
irblSuccess.ClearSelection()
End If
ElseIf AttemptType = 2 Then 'Letter
If Not iAttemptTimeLabel Is Nothing Then
iAttemptTimeLabel.Visible = False
End If
If Not itxAttemptTime Is Nothing Then
itxAttemptTime.Visible = False
End If
If Not irblSuccess Is Nothing Then
irblSuccess.Enabled = False
irblSuccess.SelectedIndex = 2
End If
End If
If Not iUpdatePanelforAttempt Is Nothing Then
iUpdatePanelforAttempt.Update()
End If
End If
End Sub
Protected Sub rblSuccessChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim iddlrncType As DropDownList = DirectCast(dvAppointment.FindControl("ddlrncType"), DropDownList)
Dim itxrncOther As TextBox = DirectCast(dvAppointment.FindControl("txrncOther"), TextBox)
Dim ilblNoContactReason As Label = DirectCast(dvAppointment.FindControl("lblNoContactReason"), Label)
Dim iUpdatePanelforAttempt As UpdatePanel = DirectCast(dvAppointment.FindControl("UpdatePanelforAttempt"), UpdatePanel)
Dim Success as Integer = -1
If Not sender.selectedValue = String.Empty Then
Success = CInt(sender.selectedValue)
If Success = 1 Then
If Not iddlrncType Is Nothing Then
iddlrncType.Visible = True
End If
If Not ilblNoContactReason Is Nothing Then
ilblNoContactReason.Visible = True
End If
Else
If Not iddlrncType Is Nothing Then
iddlrncType.Visible = False
End If
If Not ilblNoContactReason Is Nothing Then
ilblNoContactReason.Visible = False
End If
End If
If Not iUpdatePanelforAttempt Is Nothing Then
iUpdatePanelforAttempt.Update()
End If
End If
End Sub
Protected Sub ddlrncTypeChanged(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ilblSpecify As Label = CType(dvAppointment.FindControl("lblSpecify"), Label)
Dim itxrncOther As TextBox = CType(dvAppointment.FindControl("txrncOther"), TextBox)
Dim iUpdatePanelforAttempt As UpdatePanel = DirectCast(dvAppointment.FindControl("UpdatePanelforAttempt"), UpdatePanel)
Dim rncTypeID as Integer = 0
If Not sender.selectedValue = String.Empty AndAlso IsNumeric(sender.selectedvalue) Then
rncTypeID = CInt(sender.selectedValue)
If rncTypeID = 5 Then
If Not itxrncOther Is Nothing Then
itxrncOther.Visible = True
itxrncOther.Focus()
If Not ilblSpecify Is Nothing Then
ilblSpecify.Visible = True
End If
End If
Else
If Not itxrncOther Is Nothing Then
itxrncOther.Visible = False
If Not ilblSpecify Is Nothing Then
ilblSpecify.Visible = False
End If
End If
End If
If Not iUpdatePanelforAttempt Is Nothing Then
iUpdatePanelforAttempt.Update()
End If
End If
End Sub
I tried adding a second Update Panel, just around the drop-down list and the "Other" textbox, with the drop-down assigned as the AsyncPostBackTrigger, but it didn't make a difference.