I'm writing an ASP.NET web application where certain fields in the form are drop-down lists populated with values stored in a MS-SQL2000 database. I can get the lists to display correctly when the page initially loads, but the list contents disappear on PostBack. The drop-down lists themselves don't perform AutoPostBack, but there is also an ASP Calendar control on the same page, and whenever a new date is selected all the list contents disappear. To test I also tried creating just a simple testpage with only a single drop-down list, which is set to AutoPostBack, and the same thing happens--as soon as an option in the list is selected, the list contents disappear.
I'm still fairly new to programming in .NET, but putting the drop-down initialization inside the "If Not Page.IsPostBack" statement is something I've seen in several online .NET tutorials, as it saves the overhead of the database call and avoids over-writing the selected value on PostBack. But I haven't been able to find anything about how to make the drop-down lists persist, everything I've read makes it seem like the drop-down lists will just automatically persist if it's not overwritten on PostBack.
I thought maybe the problem was that I'm databinding my drop-down list to a dynamically created SqlCommand which is created inside an "If Not Page.IsPostBack" statement, so I tried making the SqlCommand and SqlConnection objects members of the web form itself, but the same thing still happens. I've also tried it with EnableViewState set to both true and false. Is something configured incorrectly on my server that's causing this problem? Here's the source from my test page:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="TestDropDown.a
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5
<form id="Form1" method="post" runat="server">
<asp:DropDownList id="DropDownList1" runat="server" DataTextField="SeminarName
Public Class TestDropDown
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
ugh()> Private Sub InitializeComponent()
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
tion As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
Dim conn As New SqlConnection(Configuratio
Dim getData As New SqlCommand("SELECT * FROM Seminars_Master", conn)
DropDownList1.DataSource = getData.ExecuteReader(Comm