Click here to Skip to main content
12,629,107 members (35,918 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET Javascript C#4.0 , +
I am setting selected item of one drop down according to the value of other drop down through javascript.
But I am not getting this selected item value in code behind.
Finally I used Hidden Field for setting the drop down value and then used this hidden field value in code behind.

Can any one explain me this behavior?

java-script code : -

for (var j = 0; j < ddlDataType.options.length; j++) 
{
 if(ddlDataType.options[j].text.toLowerCase() == 
     auditTableColumnsArray[i][0].toString().toLowerCase())
 {
    ddlDataType.options[j].selected = true;
    $get("<%= hfDataType.ClientID %>").value = ddlDataType.options[j].value;
    break;
 }
}
Posted 20-Sep-12 20:35pm
Updated 20-Sep-12 20:36pm
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Have you enabled view state of the dropdown?
if not set "EnableViewState=true" for the control.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

I think u have ur fill drop down method in page load, instead of !ispostback, check it once
  Permalink  
Comments
itskvini 22-Sep-12 1:04am
   
Well !IsPostBack, that has been a practice for a while now. So no luck there.
Actually it could not have been an issue if the setting of drop down would have been done on code behind. But we didn't want unnecessary postback. That's why doing it using javascript.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.161205.3 | Last Updated 21 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100