DJPB
DJPB

Reputation: 5799

Read Only asp drop down list

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

Upvotes: 0

Views: 2932

Answers (4)

David Mårtensson
David Mårtensson

Reputation: 7600

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

Upvotes: 0

zavaz
zavaz

Reputation: 745

Have You tried "Enabled" property of the DropDownList?

Upvotes: 0

Shadow Wizard
Shadow Wizard

Reputation: 66388

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;

Upvotes: 1

Hawxby
Hawxby

Reputation: 2804

Can't you use Enabled="false"?

Upvotes: 1

Related Questions