Sunday, March 21, 2010

Error: ASP.NET Ajax client-side framework failed to load. OR 'Sys' is undefined.

Error: ASP.NET Ajax client-side framework failed to load. OR 'Sys' is undefined. in VS 2008

Cause:

I got this error very first time when I tried to use AJAX ScriptManager object using VS2008.

I was tring to registred script using ScriptManager like below


protected void Button1_Click(object sender, EventArgs e)

{

ScriptManager.RegisterStartupScript(

this,this.GetType(),"script","alert('Hi');",true);

}

Solution:

I found there are two way to solve this error

1) You need to add httpHandlers into the web.config below "compilation" tag

Code:

<!--Ajax -->

<httpHandlers>

<remove verb="*" path="*.asmx"/>

<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions,

Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

<add verb="GET" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler" validate="false"/>

</httpHandlers>

<compilation debug="true">

2) You can solve this error by using RegisterAsyncPostBackControl method

Using beolw code button control will not have any page refresh like a client control.

Code:

protected void Page_Load(object sender, EventArgs e)

{

// register the Button1 control as one that can cause partial postbacks.

ScriptManager1.RegisterAsyncPostBackControl(Button1);

}

Note: I may not get this error in latest version/patch of VS2008.

No comments: