Setting the Textbox read only property to true using JavaScript

How do you set the Textbox read only property to true or false using JavaScript in ASP.NET?

Answers:

Answer

You can try

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

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

Answer

Try This :-

set Read Only False ( Editable TextBox)

document.getElementById("txtID").readOnly=false;

set Read Only true(Not Editable )

var v1=document.getElementById("txtID");
v1.setAttribute("readOnly","true");

This can work on IE and Firefox also.

Answer

I find that document.getElementById('textbox-id').readOnly=true sometimes doesn't work reliably.

Instead, try:

document.getElementById('textbox-id').setAttribute('readonly', 'readonly') and document.getElementById('textbox-id').removeAttribute('readonly').

A little verbose but it seems to be dependable.

Answer

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

myTextBox.Attributes.Add("readonly","readonly")
Answer

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);

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.