Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8457029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:42:08+00:00 2026-06-10T12:42:08+00:00

I am getting this 500 error: Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the

  • 0

I am getting this 500 error:

Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500

UPDATE:

My Error is actually this:
System.Web.UI.ViewStateException

if (viewStates.Length != list.Items.Count + 1)
{
    throw new ViewStateException();
}

I have been getting it ever since I added this adapter to my site that is shown on this tutorial.

ASP.NET DropDownList with OptionGroup support

It loads the DropDownList just fine in all pages but when I do any postbacks, regular or ajax is when the error appears. Here is my exact code for the adapter and the browser file.

Adapter Class

public class DropDownListAdapter : WebControlAdapter
{
    private const string OptionGroupAttribute = "OptionGroup";
    private const string TagOptionGroup = "optgroup";
    private const string AttributeLabel = "label";
    protected override void RenderContents(HtmlTextWriter writer)
    {
        DropDownList list = Control as DropDownList;
        string currentOptionGroup;
        List<string> renderedOptionGroups = new List<string>();
        foreach (ListItem item in list.Items)
        {
            Page.ClientScript.RegisterForEventValidation(
                list.UniqueID, 
                item.Value);
            if (item.Attributes[OptionGroupAttribute] == null)
            {
                RenderListItem(item, writer);
            }
            else
            {
                currentOptionGroup = item.Attributes[OptionGroupAttribute];
                if (renderedOptionGroups.Contains(currentOptionGroup))
                {
                    RenderListItem(item, writer);
                }
                else
                {
                    if (renderedOptionGroups.Count > 0)
                    {
                        RenderOptionGroupEndTag(writer);
                    }
                    RenderOptionGroupBeginTag(currentOptionGroup, writer);
                    renderedOptionGroups.Add(currentOptionGroup);
                    RenderListItem(item, writer);
                }
            }
        }
        if (renderedOptionGroups.Count > 0)
        {
            RenderOptionGroupEndTag(writer);
        }
    }

    private void RenderOptionGroupBeginTag(string name, HtmlTextWriter writer)
    {
        writer.AddAttribute(AttributeLabel, name);
        writer.RenderBeginTag(TagOptionGroup);
    }

    private void RenderOptionGroupEndTag(HtmlTextWriter writer)
    {
        writer.RenderEndTag();
    }

    private void RenderListItem(ListItem item, HtmlTextWriter writer)
    {
        foreach (string key in item.Attributes.Keys)
        {
            if (key != OptionGroupAttribute)
            {
                writer.AddAttribute(key, item.Attributes[key]);
            }
        }
        writer.AddAttribute(HtmlTextWriterAttribute.Value, item.Value, true);
        if (item.Selected)
        {
            writer.AddAttribute(HtmlTextWriterAttribute.Selected, "selected");
        }
        writer.RenderBeginTag(HtmlTextWriterTag.Option);
        writer.WriteEncodedText(item.Text);
        writer.RenderEndTag();
    }

    protected override object SaveAdapterViewState()
    {
        DropDownList list = Control as DropDownList;
        object[] viewStates = new object[list.Items.Count + 2];

        int i = 0;
        foreach (ListItem item in list.Items)
            viewStates[i++] = item.Attributes[OptionGroupAttribute];

        viewStates[i++] = base.SaveAdapterViewState();
        viewStates[i] = Hash(list.Items);

        return viewStates;
    }

    private static int Hash(ListItemCollection listItems)
    {
        int hash = 0;
        foreach (ListItem listItem in listItems)
            hash += listItem.GetHashCode();

        return hash;
    }

    object[] viewStates;

    protected override void LoadAdapterViewState(object state)
    {
        viewStates = (object[])state;
        base.LoadAdapterViewState(viewStates[viewStates.Length - 1]);
    }

    protected override void OnPreRender(System.EventArgs e)
    {
        if (viewStates != null && viewStates.Length > 1)
        {
            DropDownList list = Control as DropDownList;
            if (Page.EnableEventValidation)
            {
                if (viewStates.Length != list.Items.Count + 1)
                {
                    throw new ViewStateException();
                }
            }
            if (Hash(list.Items) == (int)viewStates[viewStates.Length - 1])
            {
                int max = viewStates.Length - 2;
                if (list.Items.Count < max)
                {
                    max = list.Items.Count;
                }
                for (int i = 0; i < max; i++)
                {
                    list.Items[i].Attributes[OptionGroupAttribute] = 
                        (string)viewStates[i];
                }
            }
        }
        base.OnPreRender(e);
    }
}

Browser File:

<browsers>
  <browser refID="default">
    <controlAdapters>
      <adapter
          controlType="System.Web.UI.WebControls.DropDownList"
          adapterType="DropDownListAdapter" />
    </controlAdapters>
  </browser>
</browsers>

StackTrace

NopSolutions.NopCommerce.Web.DropDownListAdapter.OnPreRender(EventArgs e) in ...
   // I'm guessing the issue is here
   System.Web.UI.Control.PreRenderRecursiveInternal() +8948774
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Control.PreRenderRecursiveInternal() +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496

If anyone can point me in the right direction on how to fix this that would be awesome. Now please don’t tell me to disable validateRequest because that doesn’t solve the problem it just covers it up.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:42:10+00:00Added an answer on June 10, 2026 at 12:42 pm

    You probably already solved this problem or just followed another path, but for future reference.

    In SaveAdapterViewState you save state to an object array with a length of x + 2:

    object[] viewStates = new object[list.Items.Count + 2];
    

    Then, in LoadAdapterViewState you initialize a local field viewStates with the object array coming from view state:

    viewStates = (object[])state;
    

    Finally, in OnPreRender you’re ensuring that the local field viewStates has a length of x + 1 which will fail because you saved an array of length x + 2 and that’s what you’ll get when you load it from view state.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While trying to run my application I'm getting this error. Sys.WebForms.PageRequestManagerServerErrorException:500 How can i
Getting this weird LINQ error. title = System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,System.String Here is the code I have:
I´m getting this error while trying to commit to a svn repository: svn: MKACTIVITY
I am getting this error on an existing server. No configuration change. Suddenly, it
I'm getting this error Error 500: Executing action [pay] of controller [org.gamestrike.PaymentController] caused exception:
I've got a weird problem here: I'm getting a 500 error code from Apache
With nginx/0.7.65 I'm getting this error on line 4. Why doesn't it recognize server
i am getting this error on my JS error console: DOMException code: 8 message:
Getting this error: 2009-09-03 12:44:02.307 xcodebuild[307:10b] warning: compiler 'com.apple.compilers.llvm.clang.1_0.analyzer' is based on missing compiler
Getting this error with jquery & jquery.form. Site has been live for awhile..upgraded to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.