Showing posts with label populate. Show all posts
Showing posts with label populate. Show all posts

Saturday, March 24, 2012

PageRequestManagerServerErrorException with error code 500

I am working on an ASP.NET AJAX web application. I got a PageRequestManagerServerErrorException with error code 500 every time when I try to populate a text box with a string contains some HTML tags (like <BR> for example). The full error message "Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500" appears in an alert box from javascript.
The main problem is that every next async post back generates the same error on the client side. Of course, I can check the passing string preliminarily, but my question is:
Is there a way to handle an error like this so the web application continues to run?
I have already check to clear error in Application Context on Application_Error event with Context.ClearError(), but it does not affect.

Hi!,

That exception is a callback exception and the PageRequestManager is the AJAX ScriptManager control.

You could customize the callback errors using the AsyncPostBackErrorMessage property of the ScriptManager.

Also, if you want to handle the error on server-side, use the ScriptManager_AsyncPostBackError event.

Please refer to this:http://support.microsoft.com/kb/193625

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


Hi chetan.sarode!

Thank you for your post.

Yesterday I tried to handle this error on ScriptManager_AsyncPostBackError event, but unfortunately it doesn't fire.

The only one event I found to handle is Application_Error on Global.asax. I could ClearError in current HttpContext, but it doesn't affect on client side. The error still apears after every next async post back (the only difference is that alert box in javascript with the error message doesn't appear).

So, is there a way to prevent the response from the server to the client in that case. I mean it is better for me, the server sends nothing to the client instead of an error that stops every next async post back.

I appreciate any advice.

Thanks again.


I will look into that more...

Will let u knowSmile


Hi,

I got the same error a few days ago.

The following is my code that got the error:

<%@. Page Language="C#" %>

<%@. Import Namespace="System.Xml" %>
<%@. Import Namespace="System.Data" %>
<%@. Import Namespace="System.IO" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();

//string strxml = "<books><book>asp</book><book>asp1</book><book>asp2</book></books>";
string strxml = HiddenField1.Value;//.Replace("begin", "<").Replace("end", ">").Replace("slash", "/");
//DataSet myDS = new DataSet();
//XmlTextReader xtr = new XmlTextReader(new StringReader(strxml));
//myDS.ReadXml(xtr);
//DropDownList1.DataSource = myDS;
//DropDownList1.DataValueField = "book";
//DropDownList1.DataTextField = "book";

System.Xml.XmlDocument sa = new System.Xml.XmlDocument();
sa.LoadXml(strxml);
System.Xml.XmlNodeList saa = sa.GetElementsByTagName("book");
DropDownList1.DataSource = saa;
DropDownList1.DataValueField = "InnerText";
DropDownList1.DataTextField = "InnerText";

DropDownList1.DataBind();
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>

<script language="javascript" type="text/javascript">
// <!CDATA[

function Button2_onclick() {
document.getElementById("HiddenField1").value = test.XMLDocument.xml;
// var a = "";
// while(document.getElementById("HiddenField1").value != a){
// var a = document.getElementById("HiddenField1").value;
// document.getElementById("HiddenField1").value = document.getElementById("HiddenField1").value.replace("<","begin");
// document.getElementById("HiddenField1").value = document.getElementById("HiddenField1").value.replace("/","slash");
// document.getElementById("HiddenField1").value = document.getElementById("HiddenField1").value.replace(">","end");
// }
document.getElementById("Button1").click();
}

// ]]>
</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList><div style="visibility: hidden">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</div>
<input id="Button2" type="button" value="button" onclick="return Button2_onclick();" />
<asp:HiddenField ID="HiddenField1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
<xml id="test">
<books>
<book>asp</book>
<book>asp1</book>
<book>asp2</book>
</books>
</xml>
</form>
</body>
</html>

I resolved it by changing the code into the following code:

<%@. Page Language="C#" %>

<%@. Import Namespace="System.Xml" %>
<%@. Import Namespace="System.Data" %>
<%@. Import Namespace="System.IO" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();

//string strxml = "<books><book>asp</book><book>asp1</book><book>asp2</book></books>";
string strxml = HiddenField1.Value.Replace("begin", "<").Replace("end", ">").Replace("slash", "/");

//DataSet myDS = new DataSet();
//XmlTextReader xtr = new XmlTextReader(new StringReader(strxml));
//myDS.ReadXml(xtr);
//DropDownList1.DataSource = myDS;
//DropDownList1.DataValueField = "book";
//DropDownList1.DataTextField = "book";

System.Xml.XmlDocument sa = new System.Xml.XmlDocument();
sa.LoadXml(strxml);
System.Xml.XmlNodeList saa = sa.GetElementsByTagName("book");
DropDownList1.DataSource = saa;
DropDownList1.DataValueField = "InnerText";
DropDownList1.DataTextField = "InnerText";

DropDownList1.DataBind();
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>

<script language="javascript" type="text/javascript">
// <!CDATA[

function Button2_onclick() {
document.getElementById("HiddenField1").value = test.XMLDocument.xml;
var a = "";
while(document.getElementById("HiddenField1").value != a){
var a = document.getElementById("HiddenField1").value;
document.getElementById("HiddenField1").value = document.getElementById("HiddenField1").value.replace("<","begin");
document.getElementById("HiddenField1").value = document.getElementById("HiddenField1").value.replace("/","slash");
document.getElementById("HiddenField1").value = document.getElementById("HiddenField1").value.replace(">","end");
}
document.getElementById("Button1").click();
}

// ]]>
</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList><div style="visibility: hidden">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</div>
<input id="Button2" type="button" value="button" onclick="return Button2_onclick();" />
<asp:HiddenField ID="HiddenField1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
<xml id="test">
<books>
<book>asp</book>
<book>asp1</book>
<book>asp2</book>
</books>
</xml>
</form>
</body>
</html>

For more information,seehttp://forums.asp.net/t/1126640.aspx(embedded xml datasource)

Thanks

Wednesday, March 21, 2012

Parallel Asynchronous Calls to Webservice

I'm working on a dashboard / portal system that makes use of asp.net ajax to populate the contents of the dashboard objects (dashlets, or portlets). In my javascript page load event handler, I make an asynchronous call to a web service, specifically a webmethod which returns the HTML/XML necessary to render the contents of the dashlet.


What I have is effectively the following (in pseudocode for simplicity):

on page load {

dashlet1 = service.renderFunction(dashletId1, ... );
dashlet2 = service.renderFunction(dashletId2, ... );
dashlet3 = service.renderFunction(dashletId3, ... );

...

}

However, while the page does render in an asynchronous fashion, these calls are made in sequence, so the dashlets are populated in sequence, rather than in parallel.

Is there a way to have these calls made concurrently, such that each dashlet isn't effectively waiting on the previous dashlet to have been rendered before making its own asynchronous call to the webservice? Will I have to resort to threading?


Thanks in advance for any guidance.

The problem is that browsers will only fire off two asynchronous calls at any given time. There is a good article written by the PageFlakes guy on CodeProject that detailed this issue and good design for asynchronous client-side calls:

http://www.codeproject.com/Ajax/aspnetajaxtips.asp

Hope this helps!


That's great to know - I'll read up on this article.

Thanks for the link!


have you ever been able to find a solutions for this issue? I'm facing same problem, and the artcile did not seem to help, I have only two requests, and still the first request blocks the second request completly.

Tamer


I worked around it using the CNAME hack. See more here:

http://ajaxian.com/archives/using-cnames-to-get-around-browser-connection-limits

There is no "solution" to the problem, it's an inherent limitation of current gen browsers. It's strange that you have two requests and one is being blocked. Are you sure there isn't a third call in progress?

Parital Rendering using a DataList for Trigger

Lets say I have a DataList that describes the type of a widget. I want to use that DataList to populate a list of all widgets with that type.

<

atlas:ScriptManagerID="AtlasScriptManager1"EnablePartialRendering="true"runat="Server"/><asp:DataListid="dlWidget"runat="server"RepeatColumns="4"Width="100%"><ItemTemplate><asp:LinkButtonOnCommand="PickWidget"CommandArgument='<%# DataBinder.Eval(Container.DataItem,"TypeId") %>'id="cmdGenre"runat="server">

<%

#DataBinder.Eval(Container.DataItem,"Type") %></asp:LinkButton></ItemTemplate></asp:DataList>

Here is the repeater

<atlas:UpdatePanelID="atUpdateWidget"runat="server"><ContentTemplate><asp:Repeaterid="rptPickedWidget"runat="server"Visible="False"><ItemTemplate><tr>

<tdclass="trackListing"><%#DataBinder.Eval(Container.DataItem,"WidgetName") %></td></tr></ItemTemplate></asp:Repeater></ContentTemplate><Triggers><atlas:ControlValueTriggerControlID="rptPickedWidget"PropertyName="DataSource"/></Triggers></atlas:UpdatePanel>

I have tried several different triggers and no matter what I pick the entire page refreshes. I have verified the entire page refresh both by noting the progress bar in the browser and placing a JS alert message outside of the update panel. If I change my DataList to a DropDownList and then use the SelectedValue as the Trigger the Partial Render works just fine. However in my particular case using a DropDownList isn't viable due to the number of items that it would have to contain.

Has anybody had any experience with this setup?


hello.

i assume that you made a typo because you're using the ID of the repeater instead of the datalist.

ok, back to the problem:

1. attempt number one: put the ID of the datalist on the trigger

2. if 1 doesn't work ( i really don't remember how the datalist generates the HTML, but i'm assumign that it generates a table with the ID of the control), then besides putting the ID of the datalist on the trigger, you could also try to call the registerasyncpostbackcontrol (ScriptManager class) and pass it a reference to the datalist control

note that i haven't tried any of this; if it doesn't work, come back here and, if possible, post a demo page. thanks.


Actually I did mean to put the ID of the repeater my idea was to trigger the panel to update whenever the datasource for the repeater was changed. Each time an item in the datalist is pressed the datasource on the repeater gets changed so that it displays a new set of "widgets".

I did make a little progress (and then a little regress). I used the ItemDataBound event to create a trigger for each option in the datalist. When I first load the page I can click on any of the datalist linkbutton objects and the updater panel refreshes (without reloading the whole page). Once the page has been reloaded, any subsequent click causes a full refresh. It would appear that the trigger collection gets lost.

Also, I am having some problems with Javascript not working either. Everything works just dandy on a full page load, but it is a partial render I lose JS functionality.

I really like Atlas in general and the examples show it being a really cool tool, I am just having issues getting in to real life examples.


Sorry for the double post, but I can't seem to edit my posts.

http://test.bfrd.biz/

I have set up a demonstration of what I am hoping to accomplish.


hello.

hum...not sure on what you're doing here. from your previous posts, it seems like you want to get a partial update when you change an item from the datalist, ie, you want to refresh the repeater when you selec a new thing on the datalist control. if this is what you want, then you should wrap the repeater in an udpatepanel (you're already done this) and you should also set a trigger between the panel and the datalist control. no need to set it between the panel and repeater because all the event of the repeater the require a postback (ex.: clicking on a button placed inside the repeater) should give you an automatic partial postabck.


I added the source code (see links at the top) to my example of what I would like to have happen.

http://test.bfrd.biz/DataListType.aspx

You mentioned that I should use a DataList event to fire the update, but what type of DataList event would know that I clicked on a LinkButton inside its Item Template? I was binding directly (or at least trying) to the LinkButton contained within the DataList. Hopefully the source code will help identify my intentions more clearly.

Also, to re-iterate my current problem. When the page first loads (see link above) the user is presented with a JS alert message. This is just to signify that the entire page has loaded. The user is then presented with the Products for the first Category by default. If the user clicks on any of the items in the DataList the Repeater is refreshed and the page only updates partially (no JS alert message). This appears to be working as it should, however if the user then selects another Category the entire page loads and all subsequent Category Click events cause the entire page to load. It would appear that the Trigger Collection that I populated on the Initial Page Load is not maintained by the built-in State Control. Is there a way to do this, or am I stuck?

Thanks


hello again.

well, i'm not seeing your code. what i can tell you is that during the initial loading of the page, all the links are being correclty added to the async controls collection maintained in the pagerequestmanager client object. during a partial postback, it doesn't have the correct values. that's why you're getting a full postback. what are you doing only during the initial loading of the page?


Sorry to be unclear the code is at the top ofhttp://test.bfrd.biz/DataListType.aspx. I added them in as seperate links. The reason I only populate the DataList on the initial page load, was that I didn't see the reason in getting the list of Categories each time (it doesn't change that much).

hello.

well, you'll have to run the trigger code on all the postbacks. i guess that you might change your code slighlty so that you fo through all the rows of the datalist, find the button and run the code you've already got for creating a trigger.


Ok, I added a routine that Populates the Trigger collection everytime that the Repeater is populated. But once again, the routine works the first time and the stops working on subsequent tries.

http://test.bfrd.biz/DataListType.aspx

As always the current code is available by clicking the links at the top of the page.


hello again.

hum...i think i'm starting to see the problem. if you use fiddler (or another http sniffer) you'll see that you're not getting the correct values for the asyncpostbackcontrolsids property. can you send me a small sample (with the db) to my email to see if i get any idea on how to solve this?


The current code for both the dropdown and datalist examples can be found using the buttons at the bottom of each page. The database is the Northwind example database which I got when I installed SQL 2000. I will zip up the project and send it to you once I get to work. Could you please PM me a location to send to?

Thanks for all of your help.

P.S. At least I got the code viewer control to use Atlas like I wanted it to. :)


hello.

send it to labreu at gmail.com thanks


Did you find any solution to this problem?

hello.

well, i'm almos positive that i've received the sample and i've replied...i can't seem to recall what i've said though...