Reputation: 5800
I am using a JavaScript virtual keyboard for 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.
Upvotes: 1
Views: 867
Reputation: 66641
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.
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>
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>
I tested on all my browsers and this is working also.
<asp:TextBox runat="server" ID="txtTest4"
onkeypress="return false;"></asp:TextBox>
Upvotes: 2