tags:

views:

897

answers:

5

how to set textbox readonly property true or false using javascript....in asp.net

A: 

you can try

document.getElementById("textboxid").readOnly = true;

Sridhar
A: 

Using asp.net, I believe you can do it this way :

myTextBox.Attributes.Add("readonly","readonly")
Soufiane Hassou
A: 

document.getElementById('textbox-id').readOnly=true should work

Chris
not working...do u have any other solution...
Try lowercasing the "O" in readonly. Alternatively you could try using the "disabled" attribute with true and false values. The two attributes are only subtly different (http://www.w3.org/TR/REC-html40/interact/forms.html#adef-disabled).
Chris
+1  A: 

I like jquery for things like this, see example. Depending on how your asp.net application is written, you may need to register your javascript to get this to work properly.

Mtblewis
A: 

it depends on how you trigger the event. the key you are looking is textbox.clientid.

x.aspx code

<script type="text/javascript">

   function disable_textbox(tid) {
        var mytextbox = document.getElementById(tid);
         mytextbox.disabled=false
   }
</script>

code behind x.aspx.cs

    string frameScript = "<script language='javascript'>" + "disable_textbox(" + tx.ClientID  ");</script>";
    Page.ClientScript.RegisterStartupScript(Page.GetType(), "FrameScript", frameScript);
Henry Gao