开发者

Dropdown list value when enabling and disabling through javascript

I am using a asp.net Drop down l开发者_JAVA百科ist 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.


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


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.


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.


Cofiem is right. Use something like this:

 div1.style.display = 'block';

 div2.style.display = 'none';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜