views:

61

answers:

4

I am using a asp.net Drop down list control which is disabled using javascipt, when I am trying to retrieving the value server side the default value is being set on postback.

It is a Web Project and Iam using VS2008.

A: 

Disabling a server-side control using javascript can cause the control to not be included when the server decodes the viewstate. You may need to use a HiddenControl to ensure the value is stored.

Alternatively, you could hide the drop down using css, rather than disabling it. Then the value would still exist in the postback. This may not be very good interface design, tho.

cofiem
A: 

You can enable your dropdownlist while submitting the form, i.e.:

function enable() {
    document.getElementById("ddl").removeAttribute("disabled");
}

<form id="form1" runat="server" onsubmit="enable();">

It worked for me this way.

Musa Hafalır
A: 

Cofiem is right. Use something like this:

 div1.style.display = 'block';

 div2.style.display = 'none';
IrishChieftain
+1  A: 

Standard question/answer: Do you databind your Dropdown on every Postback?! If so, check for the IsPostback property of the page in Page.Load.

Tim Schmelter
+1 - I had this same issue happen to me when it came to rebinding a GridView during postbacks on a homework assignment this past summer. I wasn't paying attention and nobody thought to point out the obvious to me. :-)
KSwift87
I am binding the drop down in page load in : If Not Page.IsPostBack Then BindMyDropdown() EndIf
skamale