Dropdown OnSelectedIndexChanged not firing
Posted
by Jim
on Stack Overflow
See other posts from Stack Overflow
or by Jim
Published on 2010-06-08T14:45:57Z
Indexed on
2010/06/08
15:12 UTC
Read the original article
Hit count: 465
The OnSelectedIndexChanged
event is not firing for my dropdown box. All forums I have looked at told me to add the AutoPostBack="true"
, but that didn't change the results.
HTML:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Current Time: " /> <br />
<asp:Label ID="lblCurrent" runat="server" Text="Label" /><br /><br />
<asp:DropDownList ID="cboSelectedLocation" runat="server" AutoPostBack="true" OnSelectedIndexChanged="cboSelectedLocation_SelectedIndexChanged" /><br /><br />
<asp:Label ID="lblSelectedTime" runat="server" Text="Label" />
</div>
</form>
</body>
</html>
Code behind:
public partial class _Default : System.Web.UI.Page
{
string _sLocation = string.Empty;
string _sCurrentLoc = string.Empty;
TimeSpan _tsSelectedTime;
protected void Page_Load(object sender, EventArgs e)
{
AddTimeZones();
cboSelectedLocation.Focus();
lblCurrent.Text = "Currently in " + _sCurrentLoc + Environment.NewLine + DateTime.Now;
lblSelectedTime.Text = _sLocation + ":" + Environment.NewLine + DateTime.UtcNow.Add(_tsSelectedTime);
}
//adds all timezone displaynames to combobox
//defaults combo location to seoul, South Korea
//defaults current location to current location
private void AddTimeZones()
{
foreach(TimeZoneInfo tz in System.TimeZoneInfo.GetSystemTimeZones())
{
string s = tz.DisplayName;
cboSelectedLocation.Items.Add(s);
if (tz.StandardName == "Korea Standard Time") cboSelectedLocation.Text = s;
if (tz.StandardName == System.TimeZone.CurrentTimeZone.StandardName) _sCurrentLoc = tz.StandardName;
}
}
//changes timezone name and time depending on what is selected in the cbobox.
protected void cboSelectedLocation_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (TimeZoneInfo tz in System.TimeZoneInfo.GetSystemTimeZones())
{
if (cboSelectedLocation.Text == tz.DisplayName)
{
_sLocation = tz.StandardName;
_tsSelectedTime = tz.GetUtcOffset(DateTime.UtcNow);
}
}
}
}
Any advice into what to look at for a rookie asp coder?
EDIT: added more code behind
© Stack Overflow or respective owner