开发者

Read Only asp drop down list

开发者 https://www.devze.com 2023-02-06 21:15 出处:网络
I\'m working on an ASP.Net app I have a drop down that, under some conditions, should be \'read only\', that is, the user can\'t change it but, on a post back its selected value can be read.

I'm working on an ASP.Net app

I have a drop down that, under some conditions, should be 'read only', that is, the user can't change it but, on a post back its selected value can be read.

Now I know that the readOnly attribute is not available for drop downs so I'm trying to build a method that simulates this

so I wanted to make a javascript function that doesnt let the user 'open' the drop down to select an item. is this possible?

here's the example

function MakeDropDownReadOnly(dropDownId, makeReadOnly){

    var myDropDown = document.getElementById(dropDownId);

    if(makeReadOnly){
        //Block drop down

    开发者_运维问答}
     else{
          //Unblock drop down
     }
}

tks


Make it disabled then in form submit (using JavaScript) enable it again so the value will be sent to the server.

Sample code to enable upon submitting:

document.getElementById("<%=DropDown1.ClientID%>").disabled = false;


Can't you use Enabled="false"?


Have You tried "Enabled" property of the DropDownList?


onfocus="this.blur()" might work to prevent a user to interact with the select.

0

精彩评论

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

关注公众号