Drop Down List Control , Select Value, and Javascript

Discussion in 'ASP .Net' started by =?Utf-8?B?Y3JhaWdAYW10ZGF0YXRlY2hub2xvZ2llcw==?=, Sep 25, 2005.

  1. Hi,

    I've been asked to create a page that dynamically populates the contents of
    related drop down lists using JavaScript, and then obviously posts things
    back to the server.

    For completeness, I re-produce example JavaScript below (this seemingly
    works fine - but just to let you see what is going on)

    e.g. var categoriesArray = TrendCategoriesHolder[intTrendIndex];
    for ( i = 0; i <= categoriesArray.length - 1; i++)
    { var categoriesObject = categoriesArray;
    var categoriesText = categoriesObject[0];
    var categoriesValue = categoriesObject[2];
    ddlTrendCategory.options = new Option(categoriesText,
    categoriesValue);
    }
    var ddlTrendType = document.getElementById("ddlTrendType");
    ddlTrendCategory.options[ddlTrendCategory.options.length] = new
    Option("All Categories", 0);


    When I post this back to the server, if i use
    ddlTrendCategory.SelectedValue.ToString() it claims it evalutates to "". If i
    use ddlTrendCategory.SelectedItem.Value.ToString() then it errors, with a
    null reference error.

    So, seemingly ASP.NET is not recognising that the drop down list has
    contents. Is there a way round this, or is the whole approach I was asked to
    do invalid and doomed to fail!

    Help appreciated. Thanks in avance.
    =?Utf-8?B?Y3JhaWdAYW10ZGF0YXRlY2hub2xvZ2llcw==?=, Sep 25, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?Y3JhaWdAYW10ZGF0YXRlY2hub2xvZ2llcw==?=

    Jéjé Guest

    you have to retrieve the value by yourself.
    like:
    request.form("mydropdown")
    will contain the selected value of the dropdown.

    if your dropdownlist is not populated from the server side, you can't use
    the server side object model. from a server side point of view, the
    dropdownlist is empty, so you can't select anything from this point of view.


    "craig@amtdatatechnologies"
    <> wrote in message
    news:...
    > Hi,
    >
    > I've been asked to create a page that dynamically populates the contents
    > of
    > related drop down lists using JavaScript, and then obviously posts things
    > back to the server.
    >
    > For completeness, I re-produce example JavaScript below (this seemingly
    > works fine - but just to let you see what is going on)
    >
    > e.g. var categoriesArray = TrendCategoriesHolder[intTrendIndex];
    > for ( i = 0; i <= categoriesArray.length - 1; i++)
    > { var categoriesObject = categoriesArray;
    > var categoriesText = categoriesObject[0];
    > var categoriesValue = categoriesObject[2];
    > ddlTrendCategory.options = new Option(categoriesText,
    > categoriesValue);
    > }
    > var ddlTrendType = document.getElementById("ddlTrendType");
    > ddlTrendCategory.options[ddlTrendCategory.options.length] = new
    > Option("All Categories", 0);
    >
    >
    > When I post this back to the server, if i use
    > ddlTrendCategory.SelectedValue.ToString() it claims it evalutates to "".
    > If i
    > use ddlTrendCategory.SelectedItem.Value.ToString() then it errors, with a
    > null reference error.
    >
    > So, seemingly ASP.NET is not recognising that the drop down list has
    > contents. Is there a way round this, or is the whole approach I was asked
    > to
    > do invalid and doomed to fail!
    >
    > Help appreciated. Thanks in avance.
    Jéjé, Sep 25, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SirPoonga
    Replies:
    2
    Views:
    751
    Ben Strackany
    Jan 7, 2005
  2. weiwei
    Replies:
    0
    Views:
    1,009
    weiwei
    Jan 5, 2007
  3. msimmons
    Replies:
    0
    Views:
    470
    msimmons
    Jul 16, 2009
  4. Replies:
    5
    Views:
    266
  5. Replies:
    3
    Views:
    284
Loading...

Share This Page