I was fighting with a drop down list on Friday, and I never did figure out what was going on.
The list contains a set of all of the states in the US and the provinces in Canada and is bound to a DataSet. The user fills out a simple form (city and state) and the clicks on search. On the post back, server side, I looked for the value of the state, and it was always set to the first value in the dataset.
First thing I found was that the list was being reloaded on the page reload. I took steps to stop that, but still, it didn't contain the value that was submitted back to the form.
I looked through all of the Request.Form values and found this:
_ctl0:_ctl2:_ctl0:ddlLocality
However, that didn't match the ddlLocality.ClientId value, which was set to this:
_ctl0__ctl2__ctl0_ddlLocality
No matter what I did, I couldn't get the locality box to post information back so that when I did a ddlLocality.SelectedValue, the value that was selected appeared, even though the value was set in in the Request.Form.
So to work around it, I did this:
for (int i=0;i < Request.Form.Count;i++)
{
if (Request.Form.Keys[i].IndexOf("ddlLocality") > 0)
{
m_selectedValue=Request.Form[i];
}
}
Then in the state load, I set the value to what I found in the query string. We're using dotnetnuke 2.1.2. Anybody have any ideas why the value wouldn't be picked up by ASP.NET?
Weird.