0

I'm working on an ASP.NET web application. Where I have added an ascx controller with an asp:updatepanel inside. The problem is now that when try to make an update it gives the following error:


MicrosoftAjax.js:5 POST http://localhost:49735/ 500 (Internal Server  Error)
    executeRequest       @ MicrosoftAjax.js:5
    executeRequest       @   MicrosoftAjax.js:5
    invoke               @ MicrosoftAjax.js:5
    _onFormSubmit        @ MicrosoftAjaxWebForms.js:5
    (anonymous function) @ MicrosoftAjax.js:5
    b                    @ MicrosoftAjax.js:5 


my ascx file looks like this:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SearchResults.ascx.cs" Inherits="CarParts24.Controls.Search.Results.SearchResults" %>

<asp:UpdatePanel ID="UpdPnlSearchResults" runat="server">
<ContentTemplate>
    <span id="search-result-json" class="hidden">
        <asp:HiddenField ID="hiddenSearchResults" runat="server" />
    </span>

    <%--<asp:Panel ID="PanelResult" runat="server">--%>

          <%-- Some ordinary HTML code --%>

    <%--</asp:Panel>--%>
</ContentTemplate>
</asp:UpdatePanel>


and the codebehind:

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CarParts24.Controls.Search.Results
{
public partial class SearchResults : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        PanelResult.Visible = false;
    }

    public void ShowResults(DataTable datatable)
    {
        hiddenSearchResults.Value = JsonConvert.SerializeObject(datatable);
        PanelResult.Visible = true;
    }
}
}
Michael Tot Korsgaard
  • 3,892
  • 11
  • 53
  • 89

1 Answers1

0

I found the problem, it was due to the <asp:HiddenField ID="hiddenSearchResults" runat="server" /> doing a postback when updating. changing it to a <asp:Literal ID="hiddenSearchResults" runat="server" /> fixed the problem

Michael Tot Korsgaard
  • 3,892
  • 11
  • 53
  • 89