an unknown error has occurred while processing the request on the server. the status code returned from the server was 500

akoIT
akoIT used Ask the Experts™
on
Hi All,

Can you help me resolve this issue on button click?

an unknown error has occurred while processing the request on the server. the status code returned from the server was 500
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Pawan KumarDatabase Expert
Awarded 2016
Top Expert 2016

Commented:
What code you have written? Can you please share.
Software Team Lead
Commented:
server was 500
most likely your server got an error and failed to generate a response

Author

Commented:
Hi Pawan thanks for response. Here is the sample code.

I have a button and an gridview inside update panel.

<asp:UpdatePanel ID="sample" runat="server" >
 <contentTemplate>

       <button type="button" runat="server" onclick="javascript: LoadingModal();" onserverclick="GenerateReport" />

     <asp:GridView ID="gridViewRpt" runat="server">
     </asp:GridView>


 </ contentTemplate>
</asp:UpdatePanel>

CODE BEHIND:

Protected Sub GenerateReport(sender as object, e as EventArgs)
........
gridViewRpt.DataSource = cmd.ExecuteReader()
gridViewRpt.DataBind()
End Sub

when i click the button on the first time, there is no error, but when i click it again this error is occured.

Author

Commented:
Hi Ryan Chong, how can I prevent this kind of error?
Ryan ChongSoftware Team Lead

Commented:
how can I prevent this kind of error?

try to verify what's the exact error generated from server end...

for example, if you can't just-in-time debugging... try do a try catch in Sub GenerateReport and send that error into a custom log file for debugging.

Just-In-Time Debugging in Visual Studio
https://msdn.microsoft.com/en-us/library/5hs4b7a6.aspx?f=255&MSPPError=-2147217396

for the custom log, we usually use log4net library which you can get from NuGet Manager.

log4net
https://www.nuget.org/packages/log4net/

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial