Virtual keyboard for label
I am using a JavaScript virtual keyboard fo开发者_如何学Gor an ASP.NET TextBox. But using a TextBox gives an option to use even system keyboard. I am trying to use an ASP.NET label instead but its not working. Is there any way to make use of virtual keyboard strictly.
Make your textbox read only.
This way your user can not type in, but the javascript from the virtual keyboard can write. This is not a very good lokking user interface thow.
Using Javascript
Second trick is to use the the onkeypress and delete the key. You can add window.event.keyCode=0
on the TextBox when the key is pressed and reset every user input.
onkeypress="window.event.keyCode=0;return false;"
Like this
<asp:TextBox runat="server" ID="txtTest2"
onkeypress="window.event.keyCode=0;return false;"></asp:TextBox>
New Version
This is works on every browser. I tested on chrome,firefox,ie
<script>
function DisableKeyboardOnMe(e)
{
try
{
if (window && window.event)
window.event.keyCode = 0;
else
e.which = 0;
}
catch(e){}
return false;
}
</script>
and
<asp:TextBox runat="server" ID="txtTest3"
onkeypress="return DisableKeyboardOnMe(event);">test</asp:TextBox>
One more simple way.
I tested on all my browsers and this is working also.
<asp:TextBox runat="server" ID="txtTest4"
onkeypress="return false;"></asp:TextBox>
精彩评论