开发者

Disabled textbox editable in IE8

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 t开发者_如何学运维he 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


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


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" />
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜