I am currently working on an old WebForms application in VB.NET. I am supposed to add a dropdown to an existing page that has been working with all controls so far. This dropdown appears in the designer and also at runtime, but when I change the selected item, the entire page gets cleared (blank white page); there is no error message. Since the page was working before, I assume the problem must be with the new dropdown.
In the CodeBehind, I also set a breakpoint at Debug.WriteLine, but no event is being triggered.
So far, I did not writy any other code that interacts with this dropdown.
If I use AutoPostBack="false", the page does not reload, but then the SelectedIndexChanged event does not fire either.
Where is the error?
<asp:DropDownList ID="ddlSomething" runat="server"
BackColor="#fff4e3" Font-Names="Verdana" Font-Size="12px"
AutoPostBack="true">
<asp:ListItem Text="unbekannt" Value="0"></asp:ListItem>
<asp:ListItem Text="enthalten" Value="1"></asp:ListItem>
<asp:ListItem Text="nicht enthalten" Value="2"></asp:ListItem>
</asp:DropDownList>
Protected WithEvents ddlSomething As Global.System.Web.UI.WebControls.DropDownList
Protected Sub ddlSomething_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlSomething.SelectedIndexChanged
Debug.WriteLine(ddlSomething.SelectedValue)
Debug.WriteLine(ddlSomething.SelectedItem)
End Sub
Edit
I also tried an AJAX approach.
<asp:ScriptManager runat="server" ID="ScriptManager1" />
<asp:UpdatePanel runat="server" ID="UpdatePanel1" ChildrenAsTriggers="True">
<ContentTemplate>
<asp:Label ID="lblsomething" runat="server" Text="some text:"
Font-Names="Verdana" Font-Size="11px"></asp:Label>
<asp:DropDownList ID="ddlSomething" runat="server"
BackColor="#fff4e3" Font-Names="Verdana" Font-Size="12px"
AutoPostBack="True" OnSelectedIndexChanged="ddlSomething_SelectedIndexChanged">
<asp:ListItem Text="unbekannt" Value="0"></asp:ListItem>
<asp:ListItem Text="enthalten" Value="1"></asp:ListItem>
<asp:ListItem Text="nicht enthalten" Value="2"></asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlSomething" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
and
Protected Sub ddlSomething_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlSomething.SelectedIndexChanged
Debug.WriteLine(ddlSomething.SelectedValue)
Debug.WriteLine(ddlSomething.SelectedItem)
End Sub