I am using ASP.Net 2.0 and C# and new to this.
I have programmatically added a zip code drop down into web form inside Page_Load method as:
ZipDropDown.Items.Add("11111");
ZipDropDown.Items.Add("22222");
ZipDropDown is the drop down control on the web page.
I have created a protected void ZipDropDown_SelectedIndexChanged(object sender, EventArgs e) method in my corresponding .cs file for the .aspx file.
protected void ZipDropDown_SelectedIndexChanged(object sender, EventArgs e)
{
string a = this.ZipDropDown.SelectedItem.Text;
string b = this.ZipDropDown.SelectedItem.Value;
}
I have set AutoPostBack as true for ZipDropDown control so that the SelectedIndexChanged gets triggered when the user changes zip code from the drop down.
My problem is, in the above code, variables a and b are not getting the correct value when the selection is changed from 11111 to 22222..
The page was populated with the value of the 11111 which is being displayed in the zip code. Then I selected 22222 from the drop down. The ZipDropDown_SelectedIndexChanged got triggered. But the variable a and b still show the value 11111 (old value for drop down), not the newly selected value 22222.
How can I get the newly selected value of 2222 from the dropdown on the server side? How can I also ensure that that new value of 2222 stays displayed in the browser in the drop down?