Friday, December 5, 2008

AJAX Exceptions


Sys.WebForms.pageRequestManager TimeoutException : the server request timed out
Solve this error by setting the executionTimeout inside ScriptManager


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.

"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.".

Solution http://siderite.blogspot.com/


Sys.WebForms.PageRequestManagerParserErrorException:
The message received from the server could not be parsed.
Common causes for the error are when the response
is modified by calls to Response.Write(), response, filters,
HttpModules, or server trace is enabled.
Details: Error parsing near '/div> | '.













Asynchronous (independent) postbacks through the "life cycle" is the same as the
regular pages. The differences occur at the time of rendering. With AJAX,
rendering happens in the partial rendering occurred in the course is in the
UpdatePanel. Render the process of using the "special form" that is only understood
by the JavaScript on the client.

When there are interfensi of the data that is sent to the client
(in the form of a special format that), the special format that will be
damaged and in the end so the client does not understand the longer format of
the data it receives. Parsing process failed and then going over munculah error.


Why it occurs http://weblogs.asp.net/leftslipper/archive/2007/02/26/sys-webforms-pagerequestmanagerparsererrorexception-what-it-is-and-how-to-avoid-it.aspx#b!

Solution http://siderite.blogspot.com/2007/02/aspnet-ajax-and-responsewrite-or.html



protected override void Render(HtmlTextWriter writer)
{

//base.Render(writer);

// render to my own text writer

HtmlTextWriter tw = new HtmlTextWriter(new StringWriter());
base.Render(tw);

/* Code 1 */
//if ( Page != null )
//{
// Page.VerifyRenderingInServerForm ( this );
//}

//base.Render ( tw );
/* Code 1 */

/* Code 2 */

// base.Render(tw); // Code 2 is replaced by code 1

/* Code 2 */

// get the Rendered content of the page

string content = tw.InnerWriter.ToString();

content = RecursiveTranslateAjax(content);
writer.Write(content);
}

private static string RecursiveTranslateAjax(string content)
{

// look for the basic Ajax response syntax

Regex reg = new Regex ( @"^(\d+)\|[^\|]*\|[^\|]*\|", RegexOptions.Singleline );
Match m = reg.Match ( content );

// if found, search deeper, by taking

// into account the length of the html text

if ( m.Success )
{

// custom method to get an integer value

int length = Int ( m.Groups [1] );

reg = new Regex ( @"^(\d+)(\|[^\|]*\|[^\|]*\|)(.{" + length + @"})\|",

RegexOptions.Singleline );

m = reg.Match ( content );

if ( m.Success )
{

string trans = Translate ( m.Groups [3].Value );
return trans.Length + m.Groups [2].Value + trans + "|" +
RecursiveTranslateAjax ( content.Substring ( m.Length ) );
}
}

// if not Ajax, just translate everything,

// it must be a normal PostBack or a string of some sort.

return Translate ( content );
}

private static bool IsNumericVariable(object o)
{
return (o is byte || o is int || o is long || o is float || o is double || o is decimal);
}

public static int Int(object o)
{

if ( o == null ) return 0;

/* const string pattern = "(^[-+]?\\d+(,?\\d*)*\\.?\\d*([Ee][-+]\\d*)?$)|(^[-+]?\\d?(,?\\d*)*\\.\\d+([Ee][-+]\\d*)?$)";
Match numberic = Regex.Match ( o.ToString (), pattern );

// Match numberic = Regex.Match(o.ToString(), "(-\\d+|\\d+)");

// if (IsNumericVariable(o)) return (int)CastDouble(o);

// if (numberic.Success) return (int)CastDouble(o);


if (numberic.Success) return Convert.ToInt32 ( ( (Capture) ( o ) ).Value );
*/
if (IsNumericVariable(o)) return Convert.ToInt32(((Capture)(o)).Value);


string s = o.ToString ();

if ( s == "" ) return 0;

Match m = Regex.Match ( s, "(-\\d+|\\d+)" );

if ( m.Success )

try
{

return Int32.Parse ( m.Groups [0].Value );

}
catch
{

}

return 0;

}

// this method only fixes the weird characters

// but you can put here any string change you would like

// like search and replace some words.

private static string Translate(string content)
{

// Html code all chars that are not ASCII, thus getting rid of strange or Unicode characters

StringBuilder sb = new StringBuilder ();

for ( int c = 0; c <> 127 ) sb.Append ( "&#" + ( (int) content [c] ) + ";" );

else sb.Append ( content [c] );

}

return sb.ToString ();

}


1 comment:

Unknown said...

Hi,
I just want to let all know that my blog has moved to https://siderite.dev. The new URLs for what you used in your post are:
https://siderite.dev
https://siderite.dev/blog/aspnet-ajax-and-responsewrite-or.html