views:

469

answers:

2

I am developing my app in asp.net web forms. The textbox is set like this

<asp:TextBox ID="txt1" runat="server" Enabled="false" ></asp:TextBox>

and this is the corresponding HTML markup

<input name="txt1" type="text" value="1.0" id="txt1" disabled="disabled" />

It is not editable upto this point.

I enable Caret browsing in IE8 (press F7) and then this field becomes editable, though the text is grayed out and consequently gives a wrong feeling to the user that the field is editable. This does not happen if I mark the textbox as readonly, but I do not want to mark it as a readonly field. Any suggestions on how to have the textbox in disabled mode when in Caret Browsing.

Edit1: I am not looking for a solution which would change IE settings/registry, am looking for a programmatic solution as my site is a public facing website

Edit2: View states are enabled for the page and for the controls

A: 

I can get you started quickly with this script:

<script> document.onkeyup = KeyCheck; 


function KeyCheck() {   alert(document.getElementById("txt1").value); }  </script> </script>

Put this all the way on top of the html. Now you get hold of the keypress. When in caret mode, IE seems to ignore the text's javascript events

ring bearer
Is this a solution ?you are just showing the textbox value on the `onkeyup` event. How does it prevent me from altering the textbox value ?
ram
See my second answer.I had given you a hint for handling this scenario in first answer.Thanks for the -ve marking!
ring bearer
A: 

Alright. I gave you a Hint to build up on. (Thanks for the -1) Here is the HTML code that you are looking for. Make sure to populate the initialVal using ASP code.

<script>
document.onkeyup = KeyCheck;       
var initialVal="1.0"

function KeyCheck()
{
    if(document.getElementById("txt1").value != initialVal) {
        document.getElementById("txt1").value = initialVal;
        return false;
    }
}   
</script>

<input name="txt1" type="text" value="1.0" id="txt1" disabled="disabled" />
ring bearer