2

I have a web form (with a master page, if that matters) with a select tag:

<select id="versionList" name="versionList""></select>

The options get dynamically appended with jQuery from a web service in response to a change event on another select control:

$.ajax ({
    url: "service.asmx/GetVersions",
    type: "POST",
    contentType: "application/json; charset=utf-8",
    data: "{'productID':'" + productID + "' }",
    dataType: "json",
    success: function(versions) {
        $("#versionList").empty();
        $.each(versions.d, function() {
        $("#versionList").append("<option value='" + this.ID + "'>" + this.Version + "</option>");
        });
    }
});

When I read the form variable during a post back, it returns "undefined":

string whereIsMyVersion = Request.Form["versionList"]; // "undefined"

I added a name attribute to the select element based on this question and expected to see the value of the option the user selected. Why do I get "undefined" instead?

If its relevant, I'm not using a DropDownList because it generates the error described here when I do the dynamic option appending.

Community
  • 1
  • 1
Evan B.
  • 163
  • 3
  • 14
  • Gah, I did something stupid. Turns out the `this.ID` in the jQuery code appending the select actually *was* undefined. I changed the property name in the web service and forgot to change it in the jQuery. – Evan B. Dec 16 '11 at 22:14

2 Answers2

0

Use Request.["versionList"], it checks all Request collections, but it should be in the Request.Form collection given that versionList is within the .NET form tag.

rick schott
  • 21,012
  • 5
  • 52
  • 81
0

is a value from the drop down list selected? if not then there is not value to post to the server.

also, is the select html element within the form when it's submitted? if not then it won't get submitted.

the only other thought I have is that webforms doesn't something hackish to the POST prior to sending where it somehow only sends data from the server generated controls. Thus ignoring your html element.

if that is the case, then place a hidden server element tag in the html and set the value to the selected option when the select element changes.

Jason Meckley
  • 7,589
  • 1
  • 24
  • 45