Try our conversational search powered by Generative AI!

asp.net ajax with EPiServer ?

Vote:
 
Hello, I am trying to get Asp.net AJAX 1.0 to work with EPiServer. I have a button within an UpdatePanel, The first time I click the button it behaves as expected, but if I click it a second time, I get an error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled. Details: Error parsing near'
#12919
Feb 01, 2007 14:11
Vote:
 
I am observing exactly the same behavior. Has anyone solved this problem?
#15087
Feb 06, 2007 10:21
Vote:
 
We've had the same problem and we've managed to work around the problem with some help from other people and sources. If you look at this URL (http://forums.asp.net/thread/1437627.aspx) you'll read about someone who've experienced the same problem in EPiServer and at the bottom of the page there is a beginning to a solution to the problem. We've created two classesm hope the following code is possible to read: using System; using System.Collections.Generic; using System.Text; using System.Web; namespace EPiServerSample.HttpModule { public class EpiServerUrlModule : IHttpModule { public EpiServerUrlModule() { } public void Dispose() { } public void Init(HttpApplication application) { application.BeginRequest += new EventHandler(application_BeginRequest); application.ReleaseRequestState += new EventHandler(InstallResponseFilter); } void application_BeginRequest(object sender, EventArgs e) { HttpContext context = ((HttpApplication)sender).Context; // original URL string url = context.Server.UrlDecode(context.Request.Url.ToString()); context.Items.Add("OriginalUrl", url); } private void InstallResponseFilter(object sender, EventArgs e) { HttpResponse response = ((HttpApplication)sender).Context.Response; if (response.ContentType == "text/html" || response.ContentType == "text/plain") { response.Filter = new Filter.AjaxPageFilter(response.Filter, (HttpApplication)sender); } } } } and... using System; using System.Text; using System.Text.RegularExpressions; using System.IO; using System.Web; using EPiServer.Core; namespace EPiServerSample.HttpModule.Filter { public class AjaxPageFilter : Stream { Stream _responseStream; long _position; StringBuilder _responseHtml; HttpApplication _httpApplication; public AjaxPageFilter(Stream inputStream, HttpApplication httpApplication) { _responseStream = inputStream; _responseHtml = new StringBuilder(); _httpApplication = httpApplication; } public override bool CanRead { get { return true; } } public override bool CanSeek { get { return true; } } public override bool CanWrite { get { return true; } } public override void Close() { _responseStream.Close(); } public override void Flush() { _responseStream.Flush(); } public override long Length { get { return 0; } } public override long Position { get { return _position; } set { _position = value; } } public override long Seek(long offset, SeekOrigin origin) { return _responseStream.Seek(offset, origin); } public override void SetLength(long length) { _responseStream.SetLength(length); } public override int Read(byte[] buffer, int offset, int count) { return _responseStream.Read(buffer, offset, count); } public override void Write(byte[] buffer, int offset, int count) { string finalHtml = System.Text.UTF8Encoding.UTF8.GetString(buffer, offset, count); { if (EPiServer.Util.FriendlyUrlModule.IsCurrentRequestFriendly) { string url = _httpApplication.Context.Request.Url.AbsoluteUri.Replace(_httpApplication.Context.Request.Url.PathAndQuery, ""); url = url.TrimEnd('/') + "/" + EPiServer.Util.FriendlyUrlModule.CurrentUrl.Trim('/') + "/" + "Post.aspx"; url = url.Replace("Post.aspx/Post.aspx", "Post.aspx").Replace("Post.aspxPost.aspx", "Post.aspx"); // Transform the response if (!String.IsNullOrEmpty(url)) { finalHtml = Regex.Replace(finalHtml, "\\|\\d+\\|formAction\\|\\|[^\\|]+\\|", "|" + url.Length.ToString() + "|formAction||" + url + "|", RegexOptions.IgnoreCase); int formIndex = finalHtml.ToLower().IndexOf("= 0) { int actionIndex = finalHtml.ToLower().IndexOf("action=\"", formIndex); if (actionIndex >= 0) { int endActionIndex = finalHtml.ToLower().IndexOf("\"", actionIndex + 8); if (endActionIndex >= 0) { finalHtml = finalHtml.Substring(0, actionIndex + 8) + url + finalHtml.Substring(endActionIndex); } } } } } } // Write the response byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(finalHtml); _responseStream.Write(data, 0, data.Length); } } } Then we've attached the HTTPModule in Web.Config like this: Hope this will help you with your problems. /Martin Emanuelsson Guide Konsult AB
#15088
Feb 06, 2007 16:14
Vote:
 
Thanks for this solutions. Works great!
#15089
Jul 05, 2007 14:25
Vote:
 
Has anyone been able to enable ASP.NET AJAX support in EPiServer CMS 5? We've tried a number of solutions, but we simply can't get it to work. As observed by others, the first partial postback works fine, but the second one fails. Also, we cannot get page method or web service calls through JavaScript to work. How come EPiServer projects don't have support for ASP.NET AJAX out of the box? Anyways, it would be sweet if someone (for instance EPiServer) could post an empty project where ASP.NET AJAX support has been added. Any help is *greatly* appreciated. /Ted
#15090
Oct 03, 2007 18:58
Vote:
 
I am having the same problem, my previous project was with Episerver 4, this solution could work, but now with Episerver CMS 5, some APIs have been re-written, it's not working any more, can anyone provide a fix or a new solution to this issue? Thanks a lot
#15091
Dec 11, 2007 0:28
Vote:
 

Hi,

I might have found a solution on the big www for this problem. Add the following to you web.config and see if it works. 

<httpModules>
<add name=”ScriptModule” type=”System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″/>
</httpModules>

That works for me, or at least has been working for about an hour. First I tried a solution with where I had a separate ajax filter which I found in the old forum. That solution did not work for when a user session timed out.

I found the solution on these two web sites:

http://ranafaisal.wordpress.com/

http://www.dotnetglobe.com/2008/02/sys_02.html 

Hope this will work for you,

--Tomas 

 

#20516
Jun 03, 2008 15:24
Vote:
 
#20519
Jun 03, 2008 18:55
Vote:
 
Just to say THANKS to Martin Emanuelsson for solution. It solved my problem related to Ajax and EPiServer 4.61. Works ok.
#22186
Jul 27, 2008 16:27
Vote:
 

AjaxPageFilter class (the second one) is somehow corrupted via my browser (cant get the paragraphs right). Could someone send it to me or rewrite it to forum? Thnx

#23144
Aug 28, 2008 8:11
Vote:
 

Here's the code for AjaxPageFilter that was mentioned in my previous post:

using System;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Web;
using EPiServer.Core;

namespace TENAOnline.HttpModule.Filter
{

public class AjaxPageFilter : Stream
{
Stream _responseStream;
long _position;
StringBuilder _responseHtml;
HttpApplication _httpApplication;

public AjaxPageFilter(Stream inputStream, HttpApplication httpApplication)
{
_responseStream = inputStream;
_responseHtml = new StringBuilder();
_httpApplication = httpApplication;
}

public override bool CanRead
{
get { return true; }
}

public override bool CanSeek
{
get { return true; }
}

public override bool CanWrite
{
get { return true; }
}

public override void Close()
{
_responseStream.Close();
}

public override void Flush()
{
_responseStream.Flush();
}

public override long Length
{
get { return 0; }
}

public override long Position
{
get { return _position; }
set { _position = value; }
}

public override long Seek(long offset, SeekOrigin origin)
{
return _responseStream.Seek(offset, origin);
}

public override void SetLength(long length)
{
_responseStream.SetLength(length);
}

public override int Read(byte[] buffer, int offset, int count)
{
return _responseStream.Read(buffer, offset, count);
}

public override void Write(byte[] buffer, int offset, int count)
{

string finalHtml = System.Text.UTF8Encoding.UTF8.GetString(buffer, offset, count);
{
if (EPiServer.Util.FriendlyUrlModule.IsCurrentRequestFriendly)
{
string url = _httpApplication.Context.Request.Url.AbsoluteUri.Replace(_httpApplication.Context.Request.Url.PathAndQuery, "");

url = url.TrimEnd('/') + "/" + EPiServer.Util.FriendlyUrlModule.CurrentUrl.Trim('/') + "/" + "Post.aspx";
url = url.Replace("Post.aspx/Post.aspx", "Post.aspx").Replace("Post.aspxPost.aspx", "Post.aspx");
// Transform the response
if (!String.IsNullOrEmpty(url))
{
finalHtml = Regex.Replace(finalHtml, "\\|\\d+\\|formAction\\|\\|[^\\|]+\\|",
"|" + url.Length.ToString() + "|formAction||" + url + "|",
RegexOptions.IgnoreCase);
int formIndex = finalHtml.ToLower().IndexOf("
if (formIndex >= 0)
{
int actionIndex = finalHtml.ToLower().IndexOf("action=\"", formIndex);
if (actionIndex >= 0)
{
int endActionIndex = finalHtml.ToLower().IndexOf("\"", actionIndex + 8);
if (endActionIndex >= 0)
{
finalHtml = finalHtml.Substring(0, actionIndex + 8) + url + finalHtml.Substring(endActionIndex);
}
}
}
}
}
}

// Write the response
byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(finalHtml);
_responseStream.Write(data, 0, data.Length);
}
}
}

#23146
Aug 28, 2008 8:34
Vote:
 

Didnt fix my problem. I have .Net 3.5. AjaxControlToolkit.dll v.3.0.20820.16598, System.Web.Extensions v.3.5.0.0. EPiServer v.4.62.0.533.

In my webconfig I have these Ajax definitions (the code button doesnt work,sry)

-----Under system.web->

    <httpHandlers>
      <remove verb="*" path="*.asmx"/>
      <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
    </httpHandlers>

---- under Pages>Controls ->

<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

---- under httpmodules ->

<add name="EpiServerUrl" type="AjaxModule.EpiServerUrlModule" />

 and registered assembly on the page that uses Ajax

<%@ Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
    Namespace="System.Web.UI" TagPrefix="asp" %>

 ----------------------

It builds fine and works fine, but not in controls like Calendar in UpdatePanel, in which it gives on second click that Sys.WebForms.PageRequestManagerParseErrorException error?

#23147
Aug 28, 2008 9:42
Vote:
 
Anyone has any idea where the problem should be? Does it differscause I have a different versions of Ajax Extensions / Toolkit?
#23544
Sep 09, 2008 10:09
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.