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

  • SEARCH
  • Home
  • 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 8370779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:59:50+00:00 2026-06-09T13:59:50+00:00

I’ve got a page with several controls, such as Checkboxlists and two containers holding

  • 0

I’ve got a page with several controls, such as Checkboxlists and two containers holding search results.

I’ve been told to make this site persistent, so the user can come back from anywhere while browsing our site and find it’s settings restored (read: boxes stll checked; results still available)

So far I have tried to override SavePageStateToPersistenceMedium and LoadPageStateFromPersitenceMedium, but I am constantly running into a yellow screen of death as soon, as I click a button on the page.

protected override void SavePageStateToPersistenceMedium(object viewState)
{
    string str = "VIEWSTATE_" + Request.UserHostAddress;
    Cache.Add(str, viewState, null, DateTime.Now.AddMinutes(Session.Timeout), TimeSpan.Zero, CacheItemPriority.Default, null);
    ClientScript.RegisterHiddenField("__VIEWSTATE_KEY", str);
    ClientScript.RegisterHiddenField("__VIEWSTATE", "");
}
protected override object LoadPageStateFromPersistenceMedium()
{
    string str = Request.Form["__VIEWSTATE_KEY"];
    if (!str.StartsWith("VIEWSTATE_"))
    {
        throw new Exception("Invalid viewstate key:" + str);
    }
    return Cache[str];
}

Is there anything wrong with my code and what would I need to call to retrieve the Viewstate on Page_Load or Page_init to retrieve it?

edit:
Here is the approach to solve it via session[“xyz”]

List<ListItem> selectItems = new List<ListItem>();
        foreach (ListItem item in CheckBoxListLevel.Items)
        {
            if (item.Selected)
                selectItems.Add(item);
        }

        Session.Add("SavedLevelItems", selectItems);

//And then in Page_Load

   if (Session["SavedLevelItems"] != null)
    {
        List<ListItem> SessionList = (List<ListItem>)Session["SavedLevelItems"];
        foreach (var item in SessionList)
        {
            if (item.Selected)
            {
                CheckBoxListLevel.Items.FindByText(item.Text).Selected = item.Selected;
            }
        }
    }

However, if I view a searchresult and then just fire a GET to get back to the initial page, all stored items are not rendered correctly.

  • 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-09T13:59:51+00:00Added an answer on June 9, 2026 at 1:59 pm

    The solution was pretty simple in the end.
    I only needed the state of some controls and not the whole page, since the results could change anytime.

    The problem was, that the datasources for the CheckBoxLists was defined in the aspx file.
    this resulted in no items being loaded when I tried to access the controls via Page_Load().

    So i transferred the whole data access logic to the code behind file, wrapped in an if statement. If a fitting session object is available the datasource is the session object, else take it from the database.

     protected void fillEntrylevelList()
    {
        using (OleDbConnection connection = new OleDbConnection(ConfigurationManager.ConnectionStrings["TestEnvironment"].ConnectionString))
        {
            string EntrylevelQuery = @"INSERT SQL STATEMENT HERE";
            OleDbCommand command = new OleDbCommand(EntrylevelQuery, connection);
            if (Session["SavedLevelItems"] != null)
                {
                    CheckBoxListLevel.Items.Clear();
                    List<ListItem> SessionList = (List<ListItem>)Session["SavedLevelItems"];
                    foreach (var item in SessionList)
                    {
                        try
                        {
                            CheckBoxListLevel.Items.Add(item);
                        }
                        catch { }
    
                    }
                }
            else
            {
                connection.Open();
                CheckBoxListLevel.DataTextField = "bez_level";
                CheckBoxListLevel.DataValueField = "id_level";
                OleDbDataReader ListReader = command.ExecuteReader();
                CheckBoxListLevel.DataSource = ListReader;
                CheckBoxListLevel.DataBind();
                ListReader.Close(); ListReader.Dispose();
                GC.Collect();
            }
        }
    }
    

    kind regards

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
i got an object with contents of html markup in it, for example: string
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I'm making a simple page using Google Maps API 3. My first. One marker

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.