FBR FBR - 5 months ago 68
ASP.NET (C#) Question

WebForms Unobtrusive Validation Mode

I encountered an error using Regular Expression Validator.

1) Create an ASP.NET Empty application (as WebApplication)
2) Add a Web Form in the WebApplication
3) Add the following line:

inside the


4) Create a folder "Script", still inside the WebApplication tree
5) Add the jquery-1.8.2.js file inside the folder
6) Inside the div below the form add two textbox:

<asp:TextBox ID="A" name="A" type="text" size="50" MaxLength="100" runat="server" />
<asp:TextBox ID="B" name="B" type="text" size="50" MaxLength="100" runat="server" />

7) For each textbox add a RegularExpressionValidator, so the code would be:

<asp:TextBox ID="A" name="A" type="text" size="50" MaxLength="100" runat="server" />
ValidationGroup="alpha" ID="ControlA"
runat="server" ErrorMessage="*" ControlToValidate="A"
<asp:TextBox ID="B" name="B" type="text" size="50" MaxLength="100" runat="server" />
ValidationGroup="beta" ID="ControlB"
runat="server" ErrorMessage="*" ControlToValidate="B"

8) create a button below the text boxes:

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />

9) In the button method "Button_click" create a string to check if it works:
protected void Button1_Click(object sender, EventArgs e)
string text = A.Text + " " + B.Text;

10) run the program.

11) any error like:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping named jquery(case-sensitive).

My version of VS is: 12.0.30501.00 Update 2.
.NET Framework: 4.5.51641
I tried with IE and Chrome, with jquery-1.8.2.js and jquery-2.1.1.js
Windows 8.1 Enterprise.

Answer Source

Remove this line in your web.config :

<add key="ValidationSettings:UnobtrusiveValidationMode" value="WebForms" />

Or add this line on your web.config :

<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />

Or in your global.asax :

ValidationSettings.UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.None
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download