Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i have added options in drop down list through jquery on runtime.
on code behind i want to access selected value of drop down list that is
generated through jquery .

but when i check selected value of drop down list at button click.
it show always first list item value as selected value.

My code on aspx page

C#
function fillmodels(){
var makeid=$("select[id$='ddlMake']").val();
PageMethods.FillModel(makeid,onsuccess,onfailed);

}

function onsuccess(res)
{

var modelList=$("select[id$='ddlModel']");
var Version=$("select[id$='ddlVersion']");

Version.empty();
Version.append("<option value='dntSave_'>----NO Version----</option>")
modelList.empty();
modelList.append("<option value='dntSave_'>----Select----</option>");

var arrModel=res.split('#');
var leng=arrModel.length;
for(var i=0;i<leng-1;i++)
{
var newOption=arrModel[i].split(',');

modelList.append("<option value="+newOption[1]+">"+newOption[0]+"</option>");
}

}
function onfailed(res)
{
alert(res.get_message());
}




code on button click

C#
protected void btn_Click(object sender, EventArgs e)
{

  string model=  ddlModel.SelectedValue.ToString();
 //every time it show model="dntSave_"
}
Posted

1 solution

This may be a silly question, but do you set the drop down values from your Page Load event in the code behind? Because if you do, I wonder if you checked the Page.IsPostback property before you did it? Because if you didn't, then every time you click the button, it will load the drop down with values and set the selected item to the first one...
 
Share this answer
 
Comments
gauravcarjinn 2-May-12 3:00am    
my brother,
i think u r right but i don't know why only drop down list that is expended to jquery and add options in this, do not hold dynamically added options after post back, but other controls such as text boxes that are assigned values through jquery hold their values after post back. can u give me it's solution
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900