Reputation: 691
I'm trying to get KeyPress Event for TextBox in ASP.NET, so I found this script, but it does not works for me
<title></title>
<script src="jquery.js" type="text/javascript"></script>
<script type="text/javascript" lang="js">
$(function () {
$("#<%=TextBox1.ClientID %>").keypress(function () {
alert("Wow; Its Work!.")
});
});
</script>
</head>
Upvotes: 3
Views: 15546
Reputation: 601
Like Mostafa wrote, it is important to insert the script at the END of the page. So that the page can register the controls first.
Upvotes: 1
Reputation: 382
try this
<asp:TextBox ID="TextBox1" runat="server" onkeypress="myFunction()"></asp:TextBox>
<script language="javascript">
function myFunction()
{
alert('Key Press')
}
</script>
Upvotes: 2
Reputation: 4703
your script is working very well the problem might be in jquery file its not found in the given location you can change the src for check
<script src="jquery.js" type="text/javascript"></script>
To
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
Upvotes: 2