The Temple of Fu

code, systems and games

Archive for September 2010

Microsoft JScript runtime 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. Ajax Toolkit – Update Panel and Datagrid download button

with 8 comments

So I have a datagrid which is a listing of files in a network share. I have a linkbutton in the grid with its text property set to a filename. This datagrid sits inside an UpdatePanel so it is all ‘Ajaxified’. When testing the command on the link button I received the following error.
Microsoft JScript runtime 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.

Now I do understand why I received this error, I had modified the output stream back to the client via AddHeader methods etc but I need to in order to get this file back to client!

Well fortunately there is a way to tell the Ajax parser code on the client that content coming back was modified on the server side via script manager and also by registering the datagrid as a postback control.

ScriptManager _scriptManager = ScriptManager.GetCurrent(this.Page); _scriptManager.RegisterPostBackControl(myDataGridID);

Hope this helps!!

Written by lordfu

September 24, 2010 at 2:11 pm

Posted in Ajax, ASP.Net, C#, Development

Internet Explorer cannot display the webpage because of fileupload size

with one comment

So I was adding an input for the file upload control. Upon upload I would check the file size against a known size limit within my application. While testing trying to exceed the maximum upload size limit I was receiving from Internet Explorer a “..cannot display the web page error.” So I tried doing a try catch within the page to see if I could catch an error but the error couldn’t be caught there. Once I figured out that the error was never going to be caught there due to the nature of the request/response cycle I thought about trying to catch the error within Global.asax but that seemed hokey considering all I wanted to do was to display a message to the user that they had exceeded the limit. Well the answer lay in the web.config. What I needed to do was tell the web server (I was using Visual Studio built in) that it’s OK to allow file uploads of ‘X’ size. Where X is larger than the maximum size you want your application to allow for file uploads, in my case 5MB. So I added the following into the
system.web element of the web.config.
httpRuntime executionTimeout="600" maxRequestLength="6000"

I then throw an InvalidOperationException when checking for file upload size and catch that within my interface and display a nice friendly “sorry too large” message.

Hope that helps!

Written by lordfu

September 24, 2010 at 10:31 am

Posted in ASP.Net, Development

Single line if statement C#

leave a comment »

Who doesn’t like doing more in one line of code!

Here is a standard if else statement in C# .

if (Age == 36)
{
isMyAge = true;
}
else
{
isMyAge = false;
}

Here is the same as a single line.

isMyAge = (Age == 36) ? true : false;

Now obviously this is not a great example because the same code above could be shortened to

isMyAge = (Age == 36);

But you get the point 🙂

Written by lordfu

September 17, 2010 at 2:49 pm

Posted in ASP.Net, C#