How To Disable Enter Key When A Asp.net Textarea Is In Readonly Mode
ASP.net: HTML generated ASP.net TextArea:
Solution 2:
$('.taskNotes').keydown(function (e) {
if ($(this).attr('readonly') === 'readonly' && e.keyCode === 13) {
e.preventDefault();
returnfalse;
}
});
You need to remove the "input" from the selector. It is a textarea. jsFiddle
To add the readonly attribute you can use:
$('.taskNotes').prop("readonly", true);
or
$('.taskNotes').attr("readonly", "readonly");
Depending on your jQuery version.
Solution 3:
If you use ASP.Net, you want to use TextBox Server Controls.
Disabled TextBox generate disabled instead of readonly. It is more suitable for your scenario.
The way you are doing is not standard in ASP.Net, and it is really fragile. You can read Disabled and read-only controls.
<asp:PanelID="Panel1" runat="server"DefaultButton="SubmitButton">
<asp:TextBoxID="MyTextArea"TextMode="multiline"Columns="50"Rows="5"runat="server" /><asp:Buttonrunat="server"ID="SubmitButton"Text="Submit"OnClick="SubmitButton_Click" />
</asp:Panel>
protectedvoidPage_Load(object sender, EventArgs e)
{
MyTextArea.Enabled = false;
}
Post a Comment for "How To Disable Enter Key When A Asp.net Textarea Is In Readonly Mode"