Wednesday, March 28, 2012

Ajax UpdatePanel PageRequestMangerServerErrorException Problem

Hello and thank you for the opportunity to post my questions. I am having a heck of a time with the Ajax UpdatePanel.

My problem is as follows:

Everything works fine until there is some period of inactivity by the user (typically 2-3 minutes) and then when the user attempts to edit a row they receive the following message:

Sys.WebForms.PageRequestMangerServerErrorException: An unkown error occured while processing the request on the server. The status code returned from the server was:500

I have tried using the code listed below with the UpdatePanel UpdateMode Property using values of Conditional and Always with the same result.

What am I missing here? Do I need to add additional code to handle ViewState issues associated with the UpdatePanel?

Any assistance would be greatly appreciated! Thank you.


CODE USED:
<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="true"
CodeFile="Default.aspx.vb" Inherits="_Default"
buffer="true" enableSessionState="true"
enableViewState="true" %>

<%@dotnet.itags.org. Register Assembly="AjaxControlToolkit"
Namespace="AjaxControlToolkit"
TagPrefix="ajaxToolkit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Ajax Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" AutoGenerateEditButton="True" DataKeyNames="ID"
DataSourceID="SqlDataSource1" GridLines="None" PageSize="20">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />
<asp:BoundField DataField="Class" HeaderText="Class" SortExpression="Class" />
<asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
UpdateCommand="UPDATE [Master] SET [LastName] = @dotnet.itags.org.LastName, [FirstName] = @dotnet.itags.org.FirstName,
[Type] = @dotnet.itags.org.Type, [Class] = @dotnet.itags.org.Class, [Status] = @dotnet.itags.org.Status
WHERE [ID] = @dotnet.itags.org.original_ID AND [LastName] = @dotnet.itags.org.original_LastName AND
[FirstName] = @dotnet.itags.org.original_FirstName AND [Type] = @dotnet.itags.org.original_Type AND
[Class] = @dotnet.itags.org.original_Class AND [Status] = @dotnet.itags.org.original_Status">
<UpdateParameters>
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="Type" Type="String" />
<asp:Parameter Name="Class" Type="String" />
<asp:Parameter Name="Status" Type="String" />
<asp:Parameter Name="original_ID" Type="Int32" />
<asp:Parameter Name="original_LastName" Type="String" />
<asp:Parameter Name="original_FirstName" Type="String" />
<asp:Parameter Name="original_Type" Type="String" />
<asp:Parameter Name="original_Class" Type="String" />
<asp:Parameter Name="original_Status" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

Try to set EnableEventValidation="false" in <%@. Page %> tag..

see results if it solves the problem...


Thank you for taking the time to respond to my question. Yes I did try that and no it did not work. I also tried EnableViewStateMac = False and other suggestions outlined in Microsoft's Knowledge Base Article # 829743 entitled "Troubleshooting the "View State is invalid" error with ASP.NET" with no success either.

I have tried searching the blogs and other sites of interest releated to Ajax. The only post which I have seen that comes the closest to addressing this issue ishttp://www.openjs.com/articles/ajax/session_timeout.php but it addresses generic Ajax and not the flavor supported by Microsoft.

Due to the fact that I am brand new to using Ajax of any kind, I tried posing on this site to attempt to find an anwser to this vexing problem.

Thank you again for taking the time to respond to my post.


Thanks...I read the article about session_timeout...

Have you tried any other solution...


Hello again. Yes, I have tried a number of things. One method that appears to work is putting a timer on the page and setting the tick for every 2 minutes or so. When the timer reaches the alarm point, it refreshes the page. The problem seems to go away. However, using this type of method could have serious performance issues if deployed accross a large number of sites and pages being hosting on the same server.

So there definately is a relationship with this problem and the viewstate. By causing the page to refresh it resets the viewstate. There must be some value caused by the async postback(s) that is offending the validation at the server a some later time. It could also be releated to the fact that the session on the server has expired and it can't find anything to refer to so it blows up.

I love being a developer but sometimes stuff like this just drives me nuts!

Any thoughts you would like to add?

Thanks for your interest in helping to solve this problem for me.


Hiwindyman42

This happens when the machineKey used to encrypt/decrypt the viewstate was changed, and more likely this will happen if you keep the page idle for a long time. To avoid this, you need to have a static machineKey.

Check this articlehttp://blog.g9th.com/2007/01/14/unable-to-validate-data-at-systemwebconfigurationmachinekeysectiongetdecodeddata.aspx

Let me know if you need more info.
You can also see this thread for more help:http://forums.asp.net/t/1115331.aspx

Thanks


Thanks Jin-Yu Yinfor providing the more details...Smile


Thank you for your response! I appologize for the delay in responding but I wanted to fully test your suggestion before replying to your post. I am very pleased to report that your suggestion does in fact FULLY FIX THE PROBLEM! The only thing that is a little puzzling however is that one of the links you provided (The Experts) said that making the MACViewState value = False has the same effect as providing a static machine key. I had tried this ealier but it was unsuccessful.

Thank you both for taking the time to provide assistance. I hope to return the favor in kind sometime in the future.

Ajax UpdatePanel does not return MS-SQL errors??

I have a datagrid wrapped in an UpdatePanel. When I try adding or editing a row that violates a check constraint, I recieve the ridiculous Sys.WebForms.PageRequestManagerPerserErrorException: the message received from the server could not parsed... instead of the MS-SQLL error message.

Is there a way to rectify this behaviour?

TIA

Hi,

Please refer to this for the reason of the error:

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

Hope this helps.

NOTE:This response contains a reference to a third partyWorld Wide Web site. Microsoft is providing this information as a convenienceto you. Microsoft does not control these sites and has not tested any softwareor information found on these sites; therefore, Microsoft cannot make anyrepresentations regarding the quality, safety, or suitability of any softwareor information found there. There are inherent dangers in the use of anysoftware found on the Internet, and Microsoft cautions you to make sure thatyou completely understand the risk before retrieving any software from theInternet.


I'm not sure about what is the inner problem of your application.
But I also face this kind of problem - 'Sys.WebForms.PageRequestManagerPerserErrorException:'. So far I
understand this happen when there is some unrecongnize html render or event occurs. I'm also not very clear.
But I solve the issue by set the attribute EnableEventValidation="false" in the ASPX page, where I place my UpdatePanel.Thanks
I'm not sure about what is the inner problem of your application.

But I also face this kind of problem - 'Sys.WebForms.PageRequestManagerPerserErrorException:'. So far I
understand this happen when there is some unrecongnize html render or event occurs. I'm also not very clear.

But I solve the issue by set the attribute EnableEventValidation="false" in the ASPX page, where I place my UpdatePanel.

Thanks

Thanks Raymond,

Yep. You can't write to the response stream when using AJAX.


Here is one more link

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

AJAX UpdatePanel and Validators - Framework Updated?

Hi Folks,

I bumped into the updatepanel/validator control issue yesterday and solved the problem by grabbing the updated validators project as per the pinned post at the top of this forum (http://forums.asp.net/t/1066821.aspx).

That said, in the post and in Scott Guthrie's blog there is mention of an official patch to ASP.NET 2.0 to fix this issue which would go out via windows update. Did this ever happen? My own dev box certainly doesn't seem to be fixed (hence having to use the compatibility validators downloaded from mattgi's site).

Cheers

Kev

I think it has because I do not have the Validator issue and I am not using the Validator library anymore. But do not hold me to it, I may have just prayed real hard for effective validation. I also like the MaskedEditValidator control too, you should check it out.


I feel like a real shoe for using someone elses code and not understanding what it's doing...

I hope I can find time to view this guys source... :(


Wow, this actually did not fix my issue -- but I know I'm using validators in the an updatepanel an getting the same issue. Grrr...


Hello.

if i'm not mistaken, you'll only get compatible validators on the 3.5 framework since the validators of 2.0 were never updated to be compatible with the updatepanel.

Ajax UpdatePanel and onload=JavaScript Function

Hi,

I am trying to work through a program but getting really stuck.

I have a asp.net (aspx) page which shows a table of data from a SQL query to the DB. This all works fine. I have a <body onload='resizediv()';> which calls a JavaScript code that resizes the DIV that the table data is displayed in - just so it adds a scrolling area if the table data is >400px deep.

This all works just fine and as it should.

So I thought I would Ajax enable it with a panelupdate control which I wrapped around the Table and DIC that displays the data from the DB. Again this all works as it should - clicking on my "refresh" control button the ajax re-loads the table data without the nasty page flicker.

BUT - my onload='resizediv();' JS function is not called when the updatepanel is refreshed ... it is called the first time the page loads but not when I click on the button control that does the refresh of the panel. Is there anyway to make this JS function fire each time the Ajax panel is updated ?

Apologies if this description is hard to understand, but I am very new to asp.net and Ajax ... :(

Thanks in advance ...

Ro

No ideas on how this could be done ? or am I just looking at this from the wrong angle ?

Thanks

Ro


Instead of using onload=..., try:

<script type="text/javascript">
Sys.Application.add_load(function() { ... });
</script>

If memory serves, the Load event should fire on initial page load as well as any async postbacks.


Steve,

Excellent reply, just tried this and indeed it works with load and partial page loads.

This will help me out no-end ....

Many thanks,

Ro

AJAX UpdatePanel - Textbox focus question - simple example

I have run across an issue recently while incorporating AJAX into one of my applications. The issue demonstrates either my fundamental lack of understanding about how this technology works, or a problem in my implementation of it. I have created an bare-bones simple example to demonstrate what I'm seeing. I know how to remedy the problem, but I'd prefer the discussion center around *WHY* it's happening.

Here are the details. Consider a project with a default.aspx. That page has two controls, Button1 and PlaceHolder1. The project also contains as usercontrol, uc1.ascx, which simply contains a TextBox control, TextBox1. The click event of Button1 dynamically loads uc1 into the placeholder via the Page.LoadControl method. All I really want to do is set focus to to TextBox1 after the control is loaded. Without the UpdatePanel, I can do it two ways. I can either put TextBox1.Focus(); in UC1's page load event, or I can register a startup javascript to find the textbox and use its focus() method. Either way works fine. See example code below.

Now introduce UpdatePanel. Enclose Button1 and PlaceHolder1 in the same UpdatePanel. The result, no focus to the textbox. Move Button1 outside of the UpdatePanel, focus will work. Fundamental question is - WHY? Why does it matter where that button control is in relation to the Placeholder and UpdatePanel. I've done a lot of searching on this topic and I've found lots of questions but not many answers. Here's the code I'm using, to get focus to work correctly, move Button1 outside of the UpdatePanel:

Default.aspx

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:UpdatePanel ID="up1" runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Text="Load UC1" OnClick="Button1_Click" />
<br />
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

Button1_Click Event:

protected void Button1_Click (object sender, EventArgs e)
{
Control ctrl = new Control();
this.PlaceHolder1.Controls.Clear();
ctrl = Page.LoadControl("uc1.ascx");
ctrl.ID = "DynamicCtrl";
this.PlaceHolder1.Controls.Add(ctrl);
}

uc1.ascx:

<%@dotnet.itags.org. Control Language="C#" AutoEventWireup="true" CodeFile="uc1.ascx.cs" Inherits="uc1" %>
UserControl 1 <br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

uc1.ascx.cs:

using System;
using System.Web.UI;

public partial class uc1 : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
//use either of these two lines in the example
//this.TextBox1.Focus();
ScriptManager.RegisterStartupScript(this, typeof(UserControl), "focus", "document.getElementById('DynamicCtrl_TextBox1').focus();", true);
}
}

OK, now I'm really annoyed and I'm punchy enough to reply to my own posts. In reading a multitude of UpdatePanel/focus related threads, I found a snipped of javascript code that I though I'd try. I inserted the following section of code in the default.aspx contained in my original post. First I inserted it in the head section of the page and that resulted in the dreaded 'Sys' is undefined message. Then I moved the javascript *below* the scriptmanager and the page loaded with no errors. Here's the code I now have inserted in default.aspx just before the end form tag:

<scripttype="text/javascript">
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_pageLoaded(pageLoaded);
function pageLoaded(sender, args)
{
if (args.get_panelsUpdated().length > 0)
{
$get('DynamicCtrl_TextBox1').focus();
}
}
</script>

So here's what is making me punchy. I try the page in IE 6 & 7, no focus to the textbox. Try in FireFox, *FOCUS WORKING CORRECTLY*!! Now that's annoying. Could someone please take a stab at either reproducing what I'm seeing or possibly explaining it?? Thanks.

...BillH


I am developing a liking to responding to my own posts - makes me feel loved.

OK, so a few minutes ago I tried something that made my above scenario work. Don't know why, but now I have textbox focus in both IE and Firefox and the solution fits within the context of the project I'm working on. I don't need any startup scripts or Focus() methods on the textbox control.

What I did was create a public accessor for TextBox1 in the user contol codebehind as such:

public TextBox t
{
get
{
return this.TextBox1;
}
}

Then I added the following one line to the Button1 click event (after the dynamic control is added to the placeholder):

this.ScriptManager1.SetFocus(((uc1)ctrl).t.ClientID);

Viola. Textbox focus in both IE7 and Firefox. No idea why, take it for what it's worth.

...BillH


Thank you so much!

I've been working on this issue for a while now... I couldn't get any of my TextBoxes inside any UpdatePanels to set focus.

The solution seems like you just have to set the focus like this:

this.ScriptManager1.SetFocus(TextBox1);

and voila it works.


Yep, that works when your textbox is on the page that's loaded. In my case, it was in a user control that was being dynamically loaded via button click events. At any rate, while your above sample would work when the control is within the same form as the ScriptManager, I would strongly suggest you explicitly pass the SetFocus method the ClientID of the control:

this.ScriptManager1.SetFocus (this.TextBox1.ClientID);

In that way if you go back and reuse this code somewhere and you have a textbox on a usercontrol or within some other dynamically loaded control it would still work.

...BillH


Many many thanks for your inputs! It really worked!Smile

AJAX update without updating viewstate

Hey,

Does someone know if it's possible to update contents on the webform without sending the viewstate and other useless stuff?

Sometimes I update only one value of a textbox. An update of the viewstate is not necessary. This is a problem; sending the viewstate again makes the reponse to slow . (it takes >500ms, and that is too slow)

Withajaxpro the response takes ~40ms. But I don't want to use both frameworks (I use ajax.asp already for the ajaxtoolkit)

I tried:

RegisterDataItem without an updatepanel update.RegisterClientScriptBlock with an updatepanel update


ps. I don't want to disable or reduce the viewstate, that isn't possible.

Hi

You can use page methods. No ViewState is transferred when invoking page method. Then update your TextBoxes with JavaScript.

Seehttp://www.singingeels.com/Articles/Using_Page_Methods_in_ASPNET_AJAX.aspx

-yuriy
http://couldbedone.blogspot.com


AH, that looks interesting. It look likes the ajaxpro method.Smile

I will post later some comparison times.

ajax update progress control with FileUpload control

Hi,

There has been a lot of posts about this in other communities as well as in asp.net forum.But I am not getting a correct picture.

By default,the fileupload and Ajax update panel does not go together,I am using a trigger where the postback trigger id is pointing to a button,which initiates the file upload.I have put an update progress control also.

But I am not seeing the update progress and the ajax behaviour is not consistent(actually its not getting).Can someone throw a light into this?

Regards

Ajith

Hi,

since you have activated the postback trigger of the update panel,it will act as a normal form and you will lose the benefit of asynchrounous effet.So,the update progress control will have no effect in this case since all the page is posted back.

In fact,this the only walkaround (that I have found) to use the fileuplod control inside an update panel.

Hope that this help you.


Hi,

So there is no point in using ajax technology there right.....

Regards

Ajith