0

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.

4
  • provide us some code(javascript,aspx) Commented Sep 14, 2010 at 12:58
  • There could be a variety of things happening here... Could you provide the JavaScript and ASP.NET code so that I could better assist you? Commented Sep 14, 2010 at 13:00
  • I have used in javscript to disable the dropdown: document.getElementById("ddlmylist").disabled = true; Commented Sep 14, 2010 at 13:07
  • ..And the code-behind (your VB.NET or C#.NET code)? Commented Sep 14, 2010 at 13:12

4 Answers 4

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

+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. :-)
I am binding the drop down in page load in : If Not Page.IsPostBack Then BindMyDropdown() EndIf
0

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.

Comments

0

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.

Comments

0

Cofiem is right. Use something like this:

 div1.style.display = 'block';

 div2.style.display = 'none';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.