I'm building a web application using Visual Studio 2012. I'm attempting to add word count into my textbox. However after adding the the javascript codes and the html codes. I receive the error as stated above.
Here is my javascript codeds
Code :
function validateLimit(obj, divID, maxchar) {
objDiv = get_object(divID);
if (this.id) obj = this;
var remaningChar = maxchar - trimEnter(obj.value).length;
if (objDiv.id) {
objDiv.innerHTML = remaningChar + " characters left";
}
if (remaningChar <= 0) {
obj.value = obj.value.substring(maxchar, 0);
if (objDiv.id) {
objDiv.innerHTML = "0 characters left";
}
return false;
}
else
{ return true; }
}
function get_object(id) {
var object = null;
if (document.layers) {
object = document.layers[id];
} else if (document.all) {
object = document.all[id];
} else if (document.getElementById) {
object = document.getElementById(id);
}
return object;
}
function trimEnter(dataStr) {
return dataStr.replace(/(\r\n|\r|\n)/g, "");
}
Server codes in master page
<script type="text/javascript" src="js/JScript.js" ></script>
ASPX codes, ( Html codes )
<tr>
<th style="width: 595px; height: 135px;">Official Report :</th>
<td colspan="4" style="height: 135px">
<asp:TextBox ID="tbofficial" runat="server" Height="121px" TextMode="MultiLine" Width="878px" MaxLength="500" ToolTip="Summary:(500 characters)" onkeyup="return validateLimit(this, 'lblMsg1', 500)" ></asp:TextBox>
<div id="lblMsg1">500 characters left</div>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="tbofficial" Display="Dynamic"
SetFocusOnError="True">*</asp:RequiredFieldValidator>
<br />
<asp:Label ID="lblmsg" runat="server"></asp:Label>
<br />
<br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
<asp:Button ID="btnClear" runat="server" Text="Clear" OnClick="btnClear_Click" />
</td>
</tr>
The ValidationSettings:UnobtrusiveValidationMode key determines the UnobtrusiveValidationMode for the entire application. The possible values are None and WebForms. The value of None indicates that unobtrusive validation is disabled whereas a value of WebForms means it is enabled.
You need a web.config key to enable the pre 4.5 validation mode.
More Info on ValidationSettings:UnobtrusiveValidationMode:
Specifies how ASP.NET globally enables the built-in validator controls to use unobtrusive JavaScript for client-side validation logic.
Type: UnobtrusiveValidationMode
Default value: None
Remarks: If this key value is set to "None" [default], the ASP.NET application will use the pre-4.5 behavior (JavaScript inline in the pages) for client-side validation logic. If this key value is set to "WebForms", ASP.NET uses HTML5 data-attributes and late bound JavaScript from an added script reference for client-side validation logic.
Example:
<appSettings> <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" /> </appSettings>
Rather than disabling a new feature, I opted to follow the instructions of the error. In my global.asax.cs I added:
protected void Application_Start(object sender, EventArgs e)
{
string JQueryVer = "1.7.1";
ScriptManager.ScriptResourceMapping.AddDefinition("jquery", new ScriptResourceDefinition
{
Path = "~/Scripts/jquery-" + JQueryVer + ".min.js",
DebugPath = "~/Scripts/jquery-" + JQueryVer + ".js",
CdnPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-" + JQueryVer + ".min.js",
CdnDebugPath = "http://ajax.aspnetcdn.com/ajax/jQuery/jquery-" + JQueryVer + ".js",
CdnSupportsSecureConnection = true,
LoadSuccessExpression = "window.jQuery"
});
}
This comes from an msdn blog post which highlights some of the advantages of script resource mappings. Of particular interest to me was centralized control over the delivery of the script files based on "debug=true", EnableCDN, etc.
There are at least three ways to disable the use of unobtrusive JavaScript for client-side validation:
<configuration>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
</configuration>
System.Web.UI.ValidationSettings.UnobtrusiveValidationMode
static property to System.Web.UI.UnobtrusiveValidationMode.None
System.Web.UI.Page.UnobtrusiveValidationMode
instance property to System.Web.UI.UnobtrusiveValidationMode.None
To disable the functionality on a per page basis, I prefer to set the Page.UnobtrusiveValidationMode
property using the page directive:
<%@ Page Language="C#" UnobtrusiveValidationMode="None" %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With