Reputation: 75
I'm working with an .aspx file and I have a text box where I want to disable line breaks. The text area I'm working with as this field:
<kcc:TextField runat="server" fieldLength="XLarge" ID="txtDBAName" maxLength="120"
TabIndex="1" />
With my changes, the jQuery function I got from a StackOverflow post I want to use is here:
<script type="text/javascript">
$(document).ready(function() {
$("#txtDBAName").keypress(function(event) {
if(event.which == '13') {
return false;
}
});
});
</script>
<kcc:TextField runat="server" fieldLength="XLarge" ID="txtDBAName" maxLength="120"
TabIndex="1" />
This issue is when I build and use the textbox, it is still allowing me to enter line breaks within the text box. Everything builds fine and there are no errors. Is there anything special I need to do when working with an aspx file?
Here is the StackOverflow post I used.
Here is a blog I read over trying to use aspx and jQuery together, but was not very helpful.
Upvotes: 0
Views: 73
Reputation: 1039298
Try replacing the hardcoded ID of your textarea:
$("#txtDBAName").keypress(...
with the actual ID generated by ASP.NET at runtime:
$("#<%= txtDBAName.ClientID %>").keypress(...
Also don't hesitate to consult the real HTML markup that ASP.NET is spitting inside the browser to see the difference between what jQuery sees as DOM and what you see as ASPX server side DOM in Visual Studio's designer (or whatever it's now called the thing allowing you to edit some aspx files in VS).
Upvotes: 1