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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:53:05+00:00 2026-06-13T02:53:05+00:00

I have a Html dropdown that will allow users to have the page size

  • 0

I have a Html dropdown that will allow users to have the page size of a grid.

@Html.DropDownList("PageSizes", Model.PageSizes)  

Then I have a javascript block:

        <script type="text/javascript">
        function ChangePageSize(size, msg) {
            alert("alert inside ChangePageSize: " + msg + " " + size); //msg = from: Initial; first dropdown change (grid updates with new page size)
                                                                       //msg = from: Initial; second dropdown  change (alert pops twice, grid does not update)
            var filterPage = "/Search/Filter";
            $.ajax({
                cache: false,
                url: filterPage,
                data: { pagesize: size },
                type: 'GET',
                success: function (data) {
                alert("success" + data);                             //this alert pops twice on the second dropdown change as well, data does have html in it.
                $('#searchResults').replaceWith(data);                       
            },
                error: function () { alert('Error changing page size.'); }
            });
        }

        $(function() {
            $('body').on('change', '#PageSizes', function() {
                var size = this.value;
                if (size != 'undefined') ChangePageSize(size, "from: Initial");
            });
        });
    </script>

This works only once. I’ve also tried using bind() and live(). Does anyone know how to rebind to the change event properly?

Update:
Modified the javascript as suggested and added some debug alerts. It seems that the function is getting bound to the event again, it also looks like the Controller Action is returning the partial view. But why isn’t my #searchResults DIV being updated again? And why does the ChangePageSize function get called twice?

Update2:
I figured out the reason my grid wasn’t populating. The DIV being specified to replace is gone after it is replaced. I crossed my fingers and surrounded the table in the partial view with a DIV with the same name and hoped the correct DIV would be found to replace.

So this is working now. I am still concerned that the function is getting called multiple times, which i’m guessing is also hitting the server multiple times. Why is that happening?

  • 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-13T02:53:06+00:00Added an answer on June 13, 2026 at 2:53 am

    change

    $(function() {
        $('#PageSizes').change(function () {
            var size = this.value;
            if (size != 'undefined')
                ChangePageSize(size);
        });
    });
    

    to

    $(function() {
        $('body').on( "change", "PageSizes", function () {
            var size = this.value;
            if (size != 'undefined')
                ChangePageSize(size);
        });
    });
    

    that way all elements with the id PageSizes will have the event handler not only thos that are present with the initial document.ready event

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

Sidebar

Related Questions

I wrote some PHP code that will allow me to create an html dropdown
I'm trying to make a HTML page (lets say index.html) that will have a
Twitter Bootstrap http://twitter.github.com/bootstrap/javascript.html#dropdown has a dropdown.js library (at http://twitter.github.com/bootstrap/1.4.0/bootstrap-dropdown.js )that will change the dropdown
I need a dropdown list on my page that will allow a user to
I have a webpage written in HTML. I have a dropdown list that is
I have multiple dropdown list: @Html.DropDownListFor(x => x.HaveColoSpace.SelectedOptions, new SelectList(Model.HaveColoSpace.Options, Value, Text), new {
To dynamically fill DropDown controls on my HTML Form, I have written code that
I am developing a site that will consist of one HTML page. The HTML
I have some html that creates a dropdown list. The list has text values
I have a <select> drop down that I'm inserting into my HTML via jQuery.

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.