11

I have a MVC4/Web API project and I created a test page that consumes the Web API using Ajax. Testing was going great, so I began working on the UI. One thing I needed to do was to populate some form controls with data returned from the Web API. I used JQuery for this.

Now, when I run the application and submit the form, I get an error indicating that the page had been updated:

Invalid postback or callback argument.  Event validation is enabled using <pages
enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %>
in a page.  For security purposes, this feature verifies that arguments to postback 
or callback events originate from the server control that originally rendered them.  
If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation
method in order to register the postback or callback data for validation.

To overcome this problem I wrapped my form controls in an UpdatePanel and added the ScriptManager control. Now I get the following errors when building:

The type or namespace name 'ScriptManager' does not exist in the namespace 
'System.Web.UI' (are you missing an assembly reference?) C:\Users\xxx\Documents\
Visual Studio 2012\Projects\xxxxxxxxx\xxxxxxxx.Web.API\Public\
xxxxxxxxxxx.aspx.designer.cs    31  41  xxxxxxxx.Web.API

and

The type or namespace name 'UpdatePanel' does not exist in the namespace 
'System.Web.UI' (are you missing an assembly reference?)    C:\Users\xxx\Documents\
Visual Studio 2012\Projects\xxxxxxxx\xxxxxxxx.Web.API\Public\
xxxxxxxxxxx.aspx.designer.cs    40  41  xxxxxxxx.Web.API

I've completely cleaned my solution. Deleted obj/Debug and obj/Release. I've researched these 2 issues and they seem to go hand-in-hand as problems that crop up a lot. I've installed the AjaxControlToolbox, but that didn't make a difference.

Is there something I have to manually add to web.config or that I should be looking for?

rwkiii
  • 5,716
  • 18
  • 65
  • 114
  • Are you using MVC or WebForms? UpdatePanel and ScriptManager are WebForms controls. – Garrison Neely Oct 01 '13 at 17:28
  • I am using MVC4. Since my Ajax code updates the contents of the form controls I get an error (above). Is there a different solution for MVC4/Web API applications? – rwkiii Oct 01 '13 at 17:31

5 Answers5

33

Add a reference to the assembly System.Web.Extensions. Select Project-> Add Reference and then select the assembly name.

6

For me the problem was that the designer had generated a row that said System.Web.UI.WebControls.ScriptManager rather than System.Web.UI.ScriptManager, which I think was because I gave it an id attribute when it doesn't need one.

Dave Cousineau
  • 12,154
  • 8
  • 64
  • 80
5

I understand why Garrison pointed out the MVC/Web Forms difference. I have some .aspx pages on my MVC site that I'm using for testing only.

But my problem was resolved by setting the target Framework of my project to 3.5 and then changing it back to 4.0 again.

rwkiii
  • 5,716
  • 18
  • 65
  • 114
  • 5
    For me the problem was that the designer had generated a row that said `System.Web.UI.WebControls.ScriptManager` rather than `System.Web.UI.ScriptManager`. (Which I think was because I gave it an id attribute when it doesn't need one.) – Dave Cousineau Apr 08 '15 at 19:01
  • 1
    This is amazing! I was upgrading from 3.5 to 4.5.2 and the switch broke the build. Now that I reverted to 3.5 and back to 4.5.2 it is working. MS can't find their a$$ with both hands. – ajeh Jun 08 '17 at 14:13
4

For me this issue comes when I copy/paste the ScriptManager and UpdatePanel blocks. The Systems.Web.Extensions reference was not pre-included in the project template, and a mere copy/paste did not add reference automatically. Adding the reference removed the error.

I am using .Net 3.5. I do not have any other framework installed so this kind of solved my problem.

Nitin Chhajer
  • 2,299
  • 1
  • 24
  • 35
4

Simply add the row

<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web"%>

in the .aspx file and rebuild!

Filiwiks
  • 65
  • 1
  • 5
  • This worked for me tonight. In addition , I isolated on making only one aspx page work successfully first. I also deleted old copies of aspx.cs and aspx.designer.cs files in the current working directory. Then I removed the Resources.Resource naming conflict by renaming to Resources.Resource5 in ./App_GlobalResources/Resource.resx. I tested my aspx pages with xsp4 --verbose instead of mod_mono_server4. Finally, I compiled with xbuild instead of MonoDevelop with the Xamarin ASP.NET addin. Please leave a comment for me and I will try to help you if needed. – Frank Jun 28 '16 at 01:32