(OR: "Don't forget about the Request.Form collection!!")

I had a strange issue the other day when working on one of my projects..

I have a dropdownlist box on an ASP.Net form that gets bound to a custom data object via AJAX call back from Telerik's RadAjaxManager object.  That part was working fine and dandy..

I also have a "submit" LinkButton object on the form that is responsible for saving all the data.  It made sense to me, that in the button's click handler, I could make a reference to the DropDownList object and get it's .SelectedValue.

So I would have used something like this:

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        string myVal = DropDownList1.SelectedValue;
        // Do My processing
    }

 

What I found out... is that in the end, .SelectedValue would always return whatever was contained in .ListIndex 0.. not what the user had actually selected.  I ended up having to go through the submitted form collection to get the "true" value..

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        string myVal = Request.Form[DropDownList1.UniqueID];
        // Do My processing
    }

 

Worked like a champ.  I'm sure that there is something silly going on with the page life cycle and resetting the DropDownList control.. But it works.. and it works well.