Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ScriptManager and UpdatePanel not found in namespace System.Web.UI

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?

like image 430
rwkiii Avatar asked Oct 01 '13 17:10

rwkiii


People also ask

Where do I put the ASP ScriptManager?

I would put the ScriptManager at the top of the Master page outside of any Multi-View. The ScriptManager is a what is used by the Microsoft controls to provide AJAX functionality.

What is ScriptManager in asp net?

ScriptManager is a server-side control that sits on your Web Form and enables the core of ASP.NET AJAX. Its primary role is the arbitration of all other ASP.NET AJAX controls on the Web Form and the addition of the right scripting libraries to the Web browser so that the client portion of ASP.NET AJAX can function.

How many ScriptManager control can be added on a asp net web page?

A page can contain only one ScriptManager control in its hierarchy.


3 Answers

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

like image 151
Abdeloihab Bourassi Avatar answered Oct 17 '22 03:10

Abdeloihab Bourassi


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.

like image 32
rwkiii Avatar answered Oct 17 '22 03:10

rwkiii


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.

like image 4
Nitin Chhajer Avatar answered Oct 17 '22 04:10

Nitin Chhajer