47

I have couple of update panels and jquery tabs on page. And also I am loading couple user controls on update panels. After user waited for couple of minutes (not checked the time approx 40 mins). when user send request from submit button it is giving below error?

'Sys.WebForms.PageRequestManagerServerErrorException:
Sys.WebForms.PageRequestManagerServerErrorException: An unknown 
error occurred while processing the request on the server. The status 
code returned from the server was: 0' when calling method: 
[nsIDOMEventListener::handleEvent]

I am not able trace this issue to fix. But I am sure. This is causing by Ajax. Gurus, if you knows solution. Please let me know.

James123
  • 11,184
  • 66
  • 189
  • 343
  • 6
    For people who view this newly - A) Check all the answers. Something might work. B) Check server logs (IIS) for the error might be suppressed – Vandesh Aug 12 '14 at 17:18
  • I also got this error when I was populating a dropdown on selection of another dropdown. For me, It was because a large set of data(around 45000 rows) was loading in grid on page load. I just removed that code and it worked fine. – Vinay Bishnoi Jun 19 '18 at 07:58
  • Check the root cause of this error from the Server's Event Viewer where application is deployed. Control Panel -> Administrative Tools -> Windows log -> Application – Sumit Jambhale Aug 14 '15 at 09:08
  • Vandesh and Sumit suggestions helped me find the source of the issue : the windows log showed me that I tried to store in session an object which wasn't marked as `Serializable`. – Ishikawa May 23 '22 at 14:05

29 Answers29

38

This issue sometimes occurs when you have a control registered as an AsyncPostbackTrigger in multiple update panels.

If that's not the problem, try adding the following right after the script manager declaration, which I found in this post by manowar83, which copies and slightly modifies this post by larryw:

<script type="text/javascript" language="javascript">
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    function EndRequestHandler(sender, args){
        if (args.get_error() != undefined){
            args.set_errorHandled(true);
        }
    }
</script>

There are a few more solutions discussed here: http://forums.asp.net/t/1066976.aspx/9/10

Makyen
  • 31,849
  • 12
  • 86
  • 121
James Johnson
  • 45,496
  • 8
  • 73
  • 110
  • 6
    I added this code. Now there is no error showing. But even postback for submit button also not happening. – James123 Oct 24 '11 at 22:05
  • This will ignore *all* errors instead of only this specific error. You may still want to report other errors ("real" errors) to the user. It would be better to check if this is the error you want to ignore, for example if (error.message.match(/Sys\.WebForms\.PageRequestManagerServerErrorException\.*Sys\.WebForms\.PageRequestManagerServerErrorException\.*unknown error.*status code returned from the server was: 0/) != -1) { args.set_errorHandled(true); } – ckarras Nov 12 '13 at 16:05
  • this is not working, it just have new error occured before the current one. – Sruit A.Suk Apr 18 '18 at 12:37
35

I had this issue and I spent hours trying to fix it.

The solution ticked as answered will not fix the error only handle it.

The best approach is to check the IIS log files and the error should be there. It appears that the update panel encapsulates the real error and outputs it as a 'javascript error'.

For instance my error was that I forgot to make a class [Serializable]. Although this worked fine locally it did not work when deployed on the server.

Kiquenet
  • 14,494
  • 35
  • 148
  • 243
Scriptworks
  • 495
  • 1
  • 6
  • 10
  • 4
    Ditto here. Looked at the Application log in Event Viewer of my IIS server and found that the ADLookup service I was calling was failing. Because this was wrapped in an Ajax call, the web front-end gave the very miscellaneous error as in original post. – Neville Sep 23 '14 at 11:12
  • 2
    Agreed. The accepted solution just ignores the error. I also found my specific issue in the Application log of the Event Viewer. – Guy Lowe Aug 16 '15 at 23:22
  • 1
    Same here--ASP logged a warning event with a stack trace that reference my code, not the AJAX code. – Tony Hinkle Dec 07 '15 at 17:06
12

I got this error when I had my button in the GridView in an UpdatePanel... deubbing my code I found that the above error is caused because of another internal error "A potentially dangerous Request.Form value was detected from the client"

Finally I figured out that one of my TextBoxes on the page has XML/HTML content and this in-turn causing above error when I removed the xml/HTML and tested the button click ... it worked as expected.

Shane Courtrille
  • 13,960
  • 22
  • 76
  • 113
RaviKumar
  • 121
  • 1
  • 3
  • has an XML/HTML what? – Shane Courtrille Sep 26 '13 at 15:51
  • 2
    @ShaneCourtrille : ASP.NET will, by default, show an error message if you attempt to submit HTML to the server with a form. For example, if you are asked to write your username, and you write `Chris`, then the page will reject the input. This is designed to protect against something called [XSS](https://www.owasp.org/index.php/XSS). An XML/HTML might be valid markup (``) or just strings that sort of look like HTML (`I like a – Chris Oct 01 '13 at 18:14
  • @Chris -- I have a similar issue, but how do you prevent this error when a user can enter content in a textarea field? Do tags need to be stripped client-side before form submission? – LoJo Jan 09 '16 at 02:05
  • @Chris Or is the only way to handle this through ValidateRequest=false and using Server.HtmlEncode/Decode? – LoJo Jan 09 '16 at 02:14
  • 1
    @LoJo This answer explains how you can allow this: http://stackoverflow.com/a/4146470/1451957 If you are building a CMS that is supposed to have HTML, then you should probably set `ValidateRequest="false"`. If you need more security (like if this is a comment on a blog), then you might want to keep the filter, or add `Server.HtmlEncode` wherever the comment is displayed. – Chris Jan 11 '16 at 13:17
  • @Chris -- Thank you for the detailed follow up. In my case we're storing plain text comments. For the moment I'm going to remove the filter and use HtmlEncoding until I have time to look into gracefully handling the error or a variant of the solution referenced. Thanks again. – LoJo Jan 11 '16 at 20:30
  • I had the same exact issue. Thank you so much for pointing it out. I had some html stored inside a hidden textbox which was giving this error (Potentially dangerous error ...). Great clue about checking the event viewer. – Himanshu Patel Jan 28 '21 at 13:04
8

This solution is helpful too:

Add validateRequest="false" in the <%@ Page directive.

This is because ASP.net examines input from the browser for dangerous values. More info in this link

fhcimolin
  • 616
  • 1
  • 8
  • 27
Shiridish
  • 4,942
  • 5
  • 33
  • 64
8

I have got the same issue, here I give my problem and my solution hoping this would help someone:

Following other people recommendation I went to the log of the server (Windows Server 2012 in my case) in :

Control Panel -> Administrative Tools -> Event Viewer

Then in the left side:

Windows Logs -> Application:

enter image description here

In the warnings I found the message from my site and in my case it was due to a null reference:

*Exception type: NullReferenceException 
Exception message: Object reference not set to an instance of an object.*

And checking at the function described in the log I found a non initialized object and that was it.

So it could be a null reference exception in the code. Hope someone find this useful, greetings.

JCO9
  • 960
  • 1
  • 15
  • 24
  • This!!! For me, I'm using JetBrains Rider and this answer inspired me to pause on all exceptions, and I could read the exception message – Sarah Sep 23 '21 at 07:31
7

Brother this piece of code is not a solution just change it to

<script type="text/javascript" language="javascript">
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    function EndRequestHandler(sender, args){
        if (args.get_error() != undefined){
            **alert(args.get_error().message.substr(args.get_error().name.length + 2));**
            args.set_errorHandled(true);
        }
    }
</script>

and you will see the error is there but you are just not throwing it on UI.

graphicdivine
  • 10,937
  • 7
  • 33
  • 59
user1341446
  • 89
  • 1
  • 1
4

I also faced the same issue , and none of these worked. In my case this was fixed by adding these lines in config file.

<appSettings>
  <add key="aspnet:MaxHttpCollectionKeys" value="100000" />
</appSettings>

<system.web.extensions>
  <scripting>   
    <scriptResourceHandler enableCompression="false" enableCaching="true"/>       
  </scripting>
</system.web.extensions> 
rns
  • 143
  • 2
  • 7
3

This is not the real problem, if you want to see why this is happening then please go to error log file of IIS.

in case of visual studio kindly navigate to:

C:\Users\User\Documents\IISExpress\TraceLogFiles\[your project name]\.

arrange file here in datewise descending and then open very first file.

it will look like:

enter image description here

now scroll down to bottom to see the GENERAL_RESPONSE_ENTITY_BUFFER it is the actual problem. now solve it the above problem will solve automatically.

enter image description here

Keith Hughitt
  • 4,860
  • 5
  • 49
  • 54
  • 1
    Thanks! Surprised this didn't have any upvotes. I wasted a lot of time on this issue but turned out I had a `Maximum request length exceeded` error. One line change in `web.config` fixed my issue. If anyone else has this issue, check [here](https://stackoverflow.com/questions/3853767/maximum-request-length-exceeded) for a fix – grizzasd Aug 16 '19 at 13:11
  • @grizzasd You're a life saver. I didn't knew that this was my problem. I have a hidden input field that had a enormous JSON string inside. I had to optimize for it to not throw the error. Kudos! – Matthew Miranda Nov 24 '20 at 04:54
3

For those using the internal IIS of Visual Studio, try the following:

  1. Generate the error message.
  2. Break the debugger at the error display.
  3. Check the callstack. You should see 'raise'.
  4. Double click 'raise'.
  5. Check the internals of 'sender' parameter. You will see a '_xmlHttpRequest' property.
  6. Open the '_xmlHttpRequest' property, and you'll see a 'response' property.
  7. The 'response' property will have the actual message.

I hope this helps someone out there!

Russ Rahn
  • 41
  • 2
2

Check your Application Event Log - my issue was Telerik RadCompression HTTP Module which I disabled in the Web.config.

PeterX
  • 2,713
  • 3
  • 32
  • 42
2

@JS5 , I also faced the same issue as you: ImageButton causing exceptions inside UpdatePanel only on production server and IE. After some research I found this:

There is an issue with ImageButtons and UpdatePanels. The update to .NET 4.5 is fixed there. It has something to do with Microsoft changed the x,y axis of a button click from Int to Double so you can tell where on the button you clicked and it's throwing a conversion error.

Source

I'm using NetFramework 2.0 and IIS 6, so, the suggested solution was to downgrade IE compatibility adding a meta tag:

<meta http-equiv="X-UA-Compatible" content="IE=9" />

I've done this via Page_Load method only on the page I needed to:

Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    Dim tag As HtmlMeta = New HtmlMeta()

    tag.HttpEquiv = "X-UA-Compatible"
    tag.Content = "IE=9"

    Header.Controls.Add(tag)
End Sub

Hope this helps someone.

Máster
  • 981
  • 11
  • 23
1

I had the same issue, when i was trying out a way to solve it, i found out that the update panel was causing this issue. Depending on my requirement i could remove the update panel and get rid of the issue. So it's a possible solution for the issue.

Hash
  • 340
  • 3
  • 8
1

We also faced the same issue, and the problem could only be reproduced in the server (i.e., not locally, which made it even harder to fix, because we could not debug the application), and when using IE. We had a page with an update panel, and within this update panel a modalpopupextender, which also contained an update panel. After trying several solutions that did not work, we fix it by replacing every imagebutton within the modalpopupextender with a linkbutton, and within it the image needed.

JS5
  • 729
  • 7
  • 17
0

Use the following code below inside updatepanel.

<script type="text/javascript" language="javascript">
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    function EndRequestHandler(sender, args){
        if (args.get_error() != undefined){
            args.set_errorHandled(true);
        }
    }
</script>
Baby Groot
  • 4,637
  • 39
  • 52
  • 71
0

For me the problem was that I was using a <button> instead of a <asp:LinkButton>

Hervé Donner
  • 523
  • 1
  • 6
  • 13
0

Some times due to some code you get HTML tags in a text filed, like I was replacing some characters with new line BR tag of HTML and by mistake I also replaced it in the text that was supposed to be displayed in a Multiline text box so my multiline text box had a new line HTML tag BR in it coming dynamically due to my string replace function and I started getting this JavaScript error and as this HTML code was displayed in a text box that was in an update panel I start getting this error so I made the correction and all was fine. So before copying pasting anything please look at your code and see that all tag are closed proper and no irrelevant code data is coming to text boxes or Drop down lists. This error always come due to ill formed tags and irrelevant data.

FarrukhMalik
  • 129
  • 1
  • 2
0

My fix for this was to remove any HTML markup that was in the Text="" property of a TextBox in my asp.net code, inside an update panel. If you have more than one update panel on a page, it will affect them all, which makes it harder to work out which panel has the issue. Chris's answer above lead me to find this, but his is a very hidden answer but I think a very relevant one so here is an answer explained.

<asp:TextBox ID="bookingTBox" runat="server" ToolTip="" Width="150px" Text="<Auto Assigned>" CssClass="textboxItalicFormat"></asp:TextBox>

The above code will give this error.

The below will not.

<asp:TextBox ID="bookingTBox" runat="server" ToolTip="" Width="150px" Text="Auto Assigned" CssClass="textboxItalicFormat"></asp:TextBox>

In the second textbox code I have removed the < and > from the Text="" property. Please try this before spending time adding lines of script code, etc.

FlashTrev
  • 507
  • 6
  • 16
0

Had this problem when using AsyncFileUploader in an iFrame. Error came when using firefox. Worked in chrome just fine. It seemed like either the parent page or iframe page was loading out of sync and the parent page could not find the controls on the iframe page. Added a simple javascript alert to say that the file was uploaded. This gave the controls enough time to load and since the controls were available, everything loaded without an error.

user3246423
  • 1
  • 1
  • 4
0

I had this issue when I upgraded my project to 4.5 framework and the GridView had Empty Data Template. Something changed and the following statement which previously was returning the Empty Data Template was now returning the Header Row.

GridViewRow dr = (GridViewRow)this.grdViewRoleMembership.Controls[0].Controls[0];

I changed it to below and the error went away and the GridView started working as expected.

GridViewRow dr = (GridViewRow)this.grdViewRoleMembership.Controls[0].Controls[1];

I hope this helps someone.

trnelson
  • 2,715
  • 2
  • 24
  • 40
Harini
  • 1
0

This issue for me was caused by a database mapping error.

I attempted to use a select() call on a datasource with errors in the code behind. My controls were within an update panel and the actual cause was hidden.

Usually, if you can temporarily remove the update panel, asp.net will return a more useful error message.

0

" 1- Go to the web.config of your application "

" 2- Add a new entry under < system.web > "

3- Also Find the pages tag and set validateRequest=False

Only this works for me. !!

Ven
  • 9
  • 1
0

Be sure to put tilde and forward slash(~/) when CDN is the root directory. I think it's an issue in IIS

0

as my friend @RaviKumar mentioned above one reason of following problem is that some piece of data transferred from code to UI contain raw html tags which make request invalid for example I had a textarea and in my code I had set its value by code below

txtAgreement.Text = Data.Agreement

And when I compiled the page I could see raw html tag inside textarea so I changed textarea to div on which innerhtml works and render html (instead of injecting raw html tags into element) and it worked for me

happy coding

Code_Worm
  • 4,069
  • 2
  • 30
  • 35
0
<add key="aspnet:MaxHttpCollectionKeys" value="100000"/ >

Add above key to Web.config or App.config to remove this error.

Akshay
  • 354
  • 3
  • 6
0

I got this error when I had ModalPopupExtender in the update panel... deubbing my code I found that the above error is caused because of updatepanel updatemode is conditional... so i change it to always then problem is solved.

Deepak_007
  • 21
  • 2
0

This was working fine in my code.. i solved my issue.. really

Add below code in web.config file.

<system.web>
    <httpRuntime executionTimeout="999" maxRequestLength="2097151"/>
</system.web>
kasim
  • 346
  • 2
  • 5
  • 23
0

answer for me was to fix a gridview control which contained a template field that had a dropdownlist which was loaded with a monstrous amount of selectable items- i replaced the DDL with a label field whose data is generated from a function. (i was originally going to allow gridview editing, but have switched to allowing edits on a separate panel displaying the DDL for that field for just that record). hope this might help someone.

0

This error: Uncaught Sys.WebForms.PageRequestManagerServerErrorException .... i got in backend logic of one UpdatePanel when Oracle made exception because of mispelled column/table in sql command....

Ivica Buljević
  • 150
  • 1
  • 8
0

In my case it was related with scriptResourceHandler compression in web.config I set to false and it looks working fine now.

<system.web.extensions> </system.web.extensions>

Sam Salim
  • 2,145
  • 22
  • 18