1

I have a cascading DropDownList in an application. The contents of the cascading drop down list is small enough that there isn't a need to use AJAX/JSON to go to a database to get the content, I am just doing it in client side javascript like this (this is a subset of the data):


var val = typeList.value; 
var applyTimeList = document.getElementById('clientid');
for (var q=applyTimeList.options.length; q>=0; q--) 
    applyTimeList.options[q]=null;

if (val == 'AutoRoute')
{
    myEle = document.createElement('option') ;
    myEle.value = 'SOP Processed';
    myEle.text = 'SOP Processed';
    applyTimeList.add(myEle) ;
} else if (val == 'Tier1Retention') {
    myEle = document.createElement('option') ;
    myEle.value = 'Study Processed';
    myEle.text = 'Study Processed';
    applyTimeList.add(myEle);
    myEle = document.createElement('option') ;
    myEle.value = 'Study Restored';
    myEle.text = 'Study Restored';
    applyTimeList.add(myEle);
    myEle = document.createElement('option') ;
    myEle.value = 'Study Archived';
    myEle.text = 'Study Archived';
    applyTimeList.add(myEle) ;
}

When I attempt to access the DropDownList on the server side I can't get the value selected, it always returns 0 as the index:


int index = RuleApplyTimeDropDownList.SelectedIndex;

How can I get the value selected on the Server side after modification?

Steve Wranovsky
  • 5,503
  • 4
  • 34
  • 52

2 Answers2

2

The value can be retrieved from the DropDownList, because the values added on the client side will not be in the ViewState. The proper way to do this is :


string selectedVal = Request[RuleApplyTimeDropDownList.UniqueID].

Steve Wranovsky
  • 5,503
  • 4
  • 34
  • 52
1

You say your want the value from the client side,

var applyTimeList = document.getElementById('clientid');
var value = applyTimeList.options[applyTimeList.selectedIndex].value;

but if you mean server-side, then you need to pick it out of the form as Steve W shows.

cdm9002
  • 1,930
  • 1
  • 15
  • 15
  • Thanks for the feedback, I intended the quest to concern how to get the selected value on the server side, not the client side. I've edited the post. – Steve Wranovsky Jul 09 '09 at 21:06