问题
I am facing one unusual problem from so many days. I have one project in asp.net. Using vb.net for code. We have used bootstrap for design purpose as well. The problem is wherever I have used the text area in page and when that page loads, The "Enter" automatically comes in it. I am showing remaining characters below the text area. For example assume there are 50 characters to enter. and when page loads and I focus to text area, the remaining characters value become one less i.e 49 here. Because one "Enter" character is there. Not getting this at all. I have debugged the code. When page rendering finish and page appears, this happens. The image is here how it looks For now When I save the text, I have removed this character. But I wanted to fix it permanently. Is that any issue because of bootstrap? Not getting this. Please any suggestions / solutions on this
Here is the script to calculate remaining characters:
function AddFact() {
if (parseInt(document.getElementById("ctl00_content_txtFact").value.length) <= 250) {
document.getElementById("ctl00_content_lblCharCnt").innerText = (250 - document.getElementById("ctl00_content_txtFact").value.length);
}
else {
document.getElementById("ctl00_content_txtFact").value = document.getElementById("ctl00_content_txtFact").value.substring(0, 250);
}
}
Here is the script below to prevent the special characters from to be entered:
function valid(f) {
if ((/[^a-zA-Z0-9_@!',.&? \n-]/g).test(f.value)) {
f.value = f.value.replace(/[^a-zA-Z0-9_@!',.&? \n-]/g, '');
document.getElementById("ctl00_content_lblErrMsg").innerText = "Special Characters are not allowed";
}
else {
document.getElementById("ctl00_content_lblErrMsg").innerText = "";
null;
}
}
Here is my HTML text area code :
<td width="25%" align="left" class="label2" style="vertical-align: top"> Add <u>F</u>act</td>
<td width="60%" valign="top" align="left" class="label2"><asp:TextBox ID="txtFact" Rows="6" Columns="50" AccessKey="F" onKeyup="AddFact()" onKeyDown="valid(this)" runat="server" style="width: 300px" TextMode="MultiLine" TabIndex="11" />
<br /> Characters Left :
<asp:Label ID="lblCharCnt" runat="server" Text="500"></asp:Label>
<br />
<br />
</td>
Thank you in advance
来源:https://stackoverflow.com/questions/42996354/unwanted-enter-character-is-adding-while-page-load-or-page-posts-back-update