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 278251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T01:12:33+00:00 2026-05-12T01:12:33+00:00

I am using jquery to append or remove a <ListItem> (rendered as <option>) from

  • 0

I am using jquery to append or remove a <ListItem> (rendered as <option>) from the <ListBox> (rendered as <select multiple=”multiple”>).

The problem arises when I try to save on PostBack. The correct information is saved to the database. However, when the page is loaded on PostBack instead of the new data from the database being loaded, the old data from the initial <ListBox> is still there.

When I set Response.Expires = 0 and refresh the page that is loaded after PostBack everything is where it needs to be.

I have tried:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Cache.Remove(“Add_Product.aspx”);

Also to bypass the problems with EventValidation I am setting EnableEventValidation=”false”.

So my question is how should I approach this problem? Is there an quick and easy way to force PostBack to load the fresh page?

I would rather not have to redirect to the same page after the PostBack.

  • 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-05-12T01:12:34+00:00Added an answer on May 12, 2026 at 1:12 am

    If you don’t want to redirect to the same page after the postback (following the Post-Redirect-Get pattern, which can actually clean ASP.NET pages up tremendously!), your best options are to:

    1) After you save the item to the database, retrieve your ListBox‘s DataSource and call ListBox.DataBind() again on the postback. (As a sidenote, the necessity of adding all this extra data retrieval and binding code is one of several reasons people move to the PRG pattern when working with ASP.NET.)

    2) Modify your codebehind class so that it adds the list item to the relevant WebControl when you post back to the page.

    That is, when you save the new value to the database, add the new ListItem to your ListBox control too:

    protected void Save_Click(object sender, EventArgs e) {
    
      // ... Code to save the new value to your database ...
      ListItem newItem = new ListItem(text, value);
      ListBox.Items.Add(listItem);
    }
    

    Now the value will be there when ASP.NET renders your HTML.


    Edit: added some more detail, to try to explain why there isn’t a better solution.

    When you add <option> elements to a <select> control on the client, those new option elements are not communicated to the server – there just isn’t any mechanism for it.

    That can be confusing because, as you’ve seen, you can still post the dynamically added option values to the server (though only if you turn off EnableEventValidation, which is risky as womp pointed out in comments).

    However, unselected option elements are not communicated to web servers during post requests.

    The question then is, how can ASP.NET rebuild the correct ListBox contents after a post request? First, it does whatever the code-behind tells it (ListBox.DataBind, ListBox.Items.Add, etc.). Second, if viewstate is enabled, it adds any option values that were saved to viewstate.

    ASP.NET could conceivably have added a third rule, “if the posted value for the select list is not already in the ListBox, add that value to the ListBox.” But since it is a security risk to allow arbitrary values to be posted to a page (at least when you have established a set of expected values, as with a ListBox), Microsoft decided against it. (Additionally, consider what you would do about dynamically added ListBox values that failed validation – should those be added when the ListBox is rebuilt or not?)

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

Sidebar

Ask A Question

Stats

  • Questions 219k
  • Answers 219k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It's a deskband. You can move it around with the… May 12, 2026 at 11:43 pm
  • Editorial Team
    Editorial Team added an answer There are read barriers and write barriers; acquire barriers and… May 12, 2026 at 11:43 pm
  • Editorial Team
    Editorial Team added an answer $('select').change(function() { alert($(this).val()); }); May 12, 2026 at 11:42 pm

Related Questions

I'm working on a web application (with ASP.NET 2.0 (C#) and jQuery) In my
I feel like this is easy but I am missing something... Using jQuery, I
I'm having issues with internet Explorer. I have a link which duplicates a file
I am using jQuery in my web application. I want to use arrays, but

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.