Showing posts with label error. Show all posts
Showing posts with label error. Show all posts

Wednesday, March 28, 2012

AJAX breaks URL rewriting : Microsoft JScript runtime error: Sys is undefined

Hey all,

My development machine is Windows XP. I'm using Intelligencia's URLRewriter.NET httpmodule to handle URL rewriting. I'm also using ScottGu's Form Control Adapter trick to catch postbacks.

Here's the problem - Sometimes, AJAX will fail. The controls inside the UpdatePanels will work. However, they will cause the whole page to refresh instead of just the area inside the UpdatePanels. This bug happens randomly. After days of working on this problem, I have not found a way to reproduce the bug. This has been very, very frustrating.

When I attach the Visual Studio debugger to IE, the page will break on this line :
Sys.WebForms.PageRequestManager._initialize('ScriptManager1', document.getElementById('form1'));

This is the error that I get :
Microsoft JScript runtime error: 'Sys' is undefined

When I try to debug the page in Firefox using the FireBug plugin, I get the five following errors :

I'll get three errors for the following line :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
One of those errors comes from WebResource.axd, and two of them come from ScriptResource.axd

I'll get a "Sys is not defined" error from my index.aspx, although FireBug apparently doesn't know which line is throwing the error.

Finally, I'll get a "Sys is not defined" error from this line in my index.aspx:
Sys.WebForms.PageRequestManager._initialize('ScriptManager1', document.getElementById('form1'));

I can solve the problem temporarily by disabling the UrlRewriter. There's a line in web.config that specifies when the URLRewriter should rewrite a URL. After I take this line out of the web.config, I'll reload a page on the site, and AJAX will be working fine again. I'll then put the line back in web.config, thus enabling the URLRewriter. AJAX will continue to work fine. In other words, by taking out the URLRewriter and putting it back in again, the problem will be solved until the next time it randomly happens again. Weird, huh?

If you have any insight at all into the nature of this problem, please let me know. Likewise, if you can tell me how to debug this monster, please let me know, as I am at an utter loss at this point.

I believe UrlRewriter allows you to add exclusions based on header data. If so, exclude any requests with the request header "X-MicrosoftAjax: Delta=true". That will prevent it from interfering with any partial postbacks.

Thanks for the advice! This bug has driven me *insane!* I swear, I must have spent at least 2 1/2 days on this thing.

Fortunately, I think I made a breakthrough today.

URLRewriter.NET requires that you specify which URLs to intercept. Naively, I had given it the following configuration :
<rewrite url="(.*)" to="${UrlTransformer($1)}" /
Basically, I had told it to intercept all incoming URLs. I think this was a mistake.

Somebody on a forum suggested that, if you get the "Sys is undefined" error, you should try to take the URL for the ScriptResource.axd file and paste it into your address bar and see what happens. When I did that, instead of being offered the opportunity to download ScriptResource.axd, I noticed that URLRewriter had picked up on the URL and was trying to do a rewrite! This could mean that IIS never properly received the request for ScriptResource.axd, and thus the client never recieved it. This would explain the JScript error and subsequent AJAX failure.

I went ahead and entered the following new configuration for URLRewriter :
<rewrite url="^(.*\.aspx)$" to="${UrlTransformer($1)}" />

So now, it's only picking up URLs that end in .aspx. So far, everything is working exactly as it should. However, I am hesitant to close the case on this for two reasons :

1) This bug has been incredibly hairy, and there have been a few other occasions where I was *sure* I had solved the problem. Thus I am hesitant to call it prematurely.
2) The incredibly random nature of the bug. This is really what made this bug so difficult; the fact that there was no reliable way to reproduce it. Even if I am correct about the cause of the bug, why in the world would it occur so randomly? I know that the browser will cache the ScriptResource.axd code. Could the bug's occurance coincide with the browsers' cache being flushed? Was this problem really more likely to occur when the network was slow, or was I just imagining things? Why would removing the line from the web.config and then replacing it again make a difference?

I may never know the answers to these questions.

In any case, thank you for your help. Your suggestion will be the first thing that I try if my current solution doesn't work.

AJAX Beta 1 error

Hello,

I just downloaded AJAX Beta 1, I have not used any of the previous Atlas version and this is my first stab at Microsoft's AJAX, on my dev machine and on the production machine I consistently get this same error message when a postback should occur from a dropdownlist:

"Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed"


I have search high and low on these forums and I can't seem to find a resolution to this. Here is the code on my aspx page that shows the scriptmanager and updatepanel:

<asp:ScriptManager id="scmAddItem" runat="server" EnablePartialRendering="True" />
<asp:UpdatePanel id="pnlCategory" runat="server" UpdateMode="Conditional" RenderMode="Inline">
<ContentTemplate>
Item Base Category : <asp:DropDownList ID="cmbItemCategory" AutoPostBack="true" OnSelectedIndexChanged="cmbItemCategory_IndexChanged" runat="server"></asp:DropDownList><br />
Choose Sub Category <asp:DropDownList ID="cmbSubCategory" runat="server"></asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>

As you can see, I have one dropdown, that when changed should fire the OnSelectedIndexChanged event, but this doesnt seem to happen, I just consistently get the above error message. I copied the sample web.config and placed the dll's in the bin folder with no results.

Anyone come across this before? Any help would be greatly appreciated.

Thanks

Sean

This weekend many people have problems with ASP.NET 2.0 AJAX, thanks Scott Guthrie for releasing something on Friday!

Do you have the problem in every page or just one? Because looks like the project is not set up properly. Got a post about setting up the Atlas projects, however I need to see if still applies to the new ASP.NET 2.0 AJAX (name to long)

http://alpascual.com/blog/al/archive/2006/07/12/Setting-up-Atlas-to-existing-Web-Projects-without-using-the-template-_2800_-Visual-Studio-2005-_2900_-.aspx

Please, let me know if that helps you, if not, I'll update the article with a new set up for ASP.NET 2.0 AJAX ( What about just calling it Atlas?)


Ok,

This is what I have found out so far, If I create a new page, and put my updatepanel in it, it updates properly as expected.

It seems to only be a problem with this one page in peticular where I have a series of complex steps setup, I was trying to add ajax functionality to it and I can't seem to get around the error message I am receiving, i am thinking perhaps it is something with ViewState?

I am doing some more testing now, and I will report back when I find the cause.

Quite strange.


I dont know if it is right solution. I had same problem. If you look at your rendered page so there is in JS method forexample
Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tctl00$cphCenter$UpdatePanel1'], [], [], 90); , but no tctl00$cphCenter$UpdatePanel1 object isn't on page. So when i am rendering the page i replace tctl00$cphCenter$UpdatePanel1 with right id ctl00$cphCenter$UpdatePanel1 without t at the begining and there is no error no more.
 
Hope this helps. If not so sorry. 

Well it seems that that T is there rightly. I have read MicrosoftAjaxWebForms.js and found it but for the moment i don't understand it. So sorry

AJAX Beta 1 and PageMethods Error

Hello,
I'm using the PageMethods to call page methods. All works with the ATLAS CTP.
With the new AJAX Beta 1 I have an error: PageMethods is undefined. I don't think it's a problem of my web.config. If i create a new ASP.NET AJAX Enabled Web Site I have the same error.

Someone have the same error? Is it a bug? Is it a beta 1 change?

Thanks,
Alessadro

hello.

make sure that your page method is public and STATIC (this is a change from the previous ctp version). btw, make sure that the method receives all the values that it needs to perform its calculations since now you don't get access to the controls maintained on the page.


I have checked all this things before posting.
My methods are public and static and have the attributes Microsoft.Web.Script.Services.ScriptMethod and WebMethod.
They use only local variables and don't access any page controls.

I think that the error is different: PageMethods is undefined. I have this javascript error, so I don't think it's a problem with my methods. It's the PageMethods that is not defined.
If i define a simple method that return an integer, I have the same error. And I have the same error if i create a new ASP.NET AJAX Enabled web site project too.


hello again.

if i recall correctly, you just need to use the webmethod. here's a quick example i have here:

<%@. Page Language="C#" %>
<%@. Import namespace="LivroAtlas"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
[System.Web.Services.WebMethod]
public static Aluno[] ObtemAlunos()
{
Aluno[] alunos = new Aluno[]{
new Aluno( "João", 15 ),
new Aluno( "Rita", 16 ),
};

return alunos;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="manager" />
<input type="button" value="invocar método da página" onclick="handle()" />
</form>
<script type="text/javascript">
function handle()
{
PageMethods.ObtemAlunos( handleCallback);
}
function handleCallback( res )
{
for( var i = 0; i < res.length; i++ )
{
alert( res[i].Nome + "-" + res[i].Idade );
}
}
</script>
</body>
</html>

btw, if you check the source of your page and don't see the global variable PageMethods, then that means that the ScriptManager is not injecting the proxy for the methods on the client side...


Finally I resolved the problem.
The solution is describe in this post from Shawn Burke's Blog. Due to a bug in this release of AJAX the page method must be in the same ASPX Page and not in codebehind.


Did you do anything to get the PageMethods object to appear on your page?

I've got public static void, I've got WebMethod and ScriptMethod, and I've got the function in the page rather than the code-behind... still nothing.


what the.......

okay... apparently closing the project, leaving it overnight, and changing absolutely nothing... fixed it... what do ya know. :p


This will break too much of my code...I think I will revert back to ATLAS until this is resolved/changed.

Monday, March 26, 2012

Ajax AutoCompleteExtender

Hello!

I have a problem about AjaxAutoComplete.

In my project,I have no error till I put three AutoCompleteExtender.

But when more than 3, I meet "Operation Aborted" MessageBox.

Please help me if you can be quickly.

Thanks

For regards,

Hi,

Without any valuable information, it is hard to say where the problem lies on.

Please provide any more information,eg. any code of this.

Thanks!


Hello!

many many thanks for your reply!

Please forgive me not for reply a once.i find your reply just now.

In my project,there are 3 pages.first page is list page .from this page ,we can go second page to entry data into DB. and then from first page,we can also third page to edit data from DB.

In second page and third page,I used AutoCompleteExtender.

In these pages ,I need to use 5 AutoCompleteExtender .So i used 5.But I found " Operation Aborted" Message when I went more than 3 times these pages .that is ,first I entry,and second time I edit and then third time i entry and up to this time i have no error.but forth time i edit ,In that time Edit Page come on but same time i find "Operation Aborted" MessageBox ,After that,I find "The Page cannot be display".

Some Codes In Pages

<asp:TextBoxid="txt1"runat="server" cssclass="MagicColText"width="30px"maxlength="3"></asp:TextBox>

<ajaxToolkit:AutoCompleteExtenderid="Complete1"CompletionSetCount="10"runat="server"TargetControlID="txt1"ServicePath="WebService.asmx"ServiceMethod="GetCompletion1"MinimumPrefixLength="1"CompletionInterval="1000"EnableCaching="true"></ajaxToolkit:AutoCompleteExtender>

<asp:TextBoxid="txt2"runat="server" cssclass="MagicColText"width="30px"maxlength="3"></asp:TextBox>

<ajaxToolkit:AutoCompleteExtenderid="Complete2"CompletionSetCount="10"runat="server"TargetControlID="txt2"ServicePath="WebService.asmx"ServiceMethod="GetCompletion2"MinimumPrefixLength="1"CompletionInterval="2000"EnableCaching="true"></ajaxToolkit:AutoCompleteExtender>

<asp:TextBoxid="txt3"runat="server" cssclass="MagicColText"width="30px"maxlength="3"></asp:TextBox>

<ajaxToolkit:AutoCompleteExtenderid="Complete3"CompletionSetCount="10"runat="server"TargetControlID="txt3"ServicePath="WebService.asmx"ServiceMethod="GetCompletion3"MinimumPrefixLength="1"CompletionInterval=3000"EnableCaching="true"></ajaxToolkit:AutoCompleteExtender>

and so on....

I used till 5.I don't find error till 3 .

IS there any rules in property of AutoCompleteExtender?

and then i don't understand CompletionInterval!

pls help me!

many thanks!

Best regards,

Saturday, March 24, 2012

ajax and login

when i try to put login inside updatepanel get error message

in old version (atlas) login work cool if u enabledauthenticationService in web.config

<authenticationServiceenabled="true" />

any one can help please

hello.
are you talking about the asp login control? If so, i think it doesn't depend on the <authenticationService>?element...

Ajax and HttpModules help needed

Hello, Smile

I created a HttpModule that uses an IHttpModule to add content to the start of the webpage, but i get the error of:

Sys.webforms.pagerequestmanagerparsererrorexception: The message received from the server could not be parsed. Common causes for this error are when the response if modified by calls to response.write(), response filters, httpmodules, or server trace is enabled. Details: Error parsing near '<h4>Request Begins

I tried to put the AJAX ScriptModule before and also after but I still cannot get this to work

Is there something i need to do to make this work, or am I just out of luck because you cannot change or add to the page due to AJAX

The code I am using is:


Implements IHttpModule


Public Sub Dispose() Implements IHttpModule.Dispose
' add clean-up code here if required
End Sub

Public Sub Init(ByVal app As HttpApplication) Implements IHttpModule.Init

AddHandler app.BeginRequest, AddressOf MyBeginRequest
End Sub

Public Sub MyBeginRequest(ByVal s As Object, ByVal e As EventArgs)
Dim app As HttpApplication
app = CType(s, HttpApplication)

app.Response.Write ("<h4>Request Begins Here...</h4>")
End Sub

Hi Tdar,

Check out thishttp://weblogs.asp.net/leftslipper/archive/2007/02/26/sys-webforms-pagerequestmanagerparsererrorexception-what-it-is-and-how-to-avoid-it.aspx

Hope this helps,