Implementing a Masonry layout within an ASP UpdatePanel

I have an ASP-WebPage where I'm using an UpdatePanel with a Dropdown and Output-Div for dynamically generated Cards. These cards are layouted by Masonry. The content of the Output-Div is bound to the Dropdown selection.

Initially, the Masonry-Layout works fine on PageLoad. However, when the Dropdown is changed, the layout breaks and spaces between the cards appear.

I've attempted to trigger the layout method of the Masonry object after the content of the output-div changes. It seems that this method is not being executed inside the UpdatePanel.

Could someone provide me with a suggestion on how to ensure that the Masonry layout is re-applied after changes in the update panel?

This is how I have implemented it:

<asp:ScriptManager runat="server" EnablePageMethods="false"/>
        <asp:UpdatePanel runat="server">
            <ContentTemplate>
               <asp:DropDownList OnSelectedIndexChanged="ddKat_SelectedIndexChanged" OnDataBound="ddKat_DataBound" ID="ddKat" CssClass="form-control" runat="server" DataSourceID="SqlDataSource1" DataTextField="name" DataValueField="id" AutoPostBack="true">
            </asp:DropDownList>
            <asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString='<%$ ConnectionStrings:comidosDElocalConnectionString %>' SelectCommand="SELECT [id], [name] FROM [kategorien] order by name"></asp:SqlDataSource>
               <div class="wrapper" id="wrapper">
                <!-- Start Blog Masonry Area -->
                <section class="blog__masonery__area bg--white section-padding--lg">
                    <div class="container blog__masonry__container">
                        <div class="row blog__masonery__wrap" id="ausgabe" runat="server">

                        </div>
                    </div>
                </section>
                <!-- End Blog Masonry Area -->     
            </div><!-- //Main wrapper -->
            </ContentTemplate>
        </asp:UpdatePanel>

protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            List<kategorien> listeKategorien = myKATEGORIE.holeKategorienMitContent();
            foreach (var item in listeKategorien)
            {
                ausgabeNav.Controls.Add(erzeugeNavZuKategorie_id(item));
            }
        }
    }


protected void ddKat_SelectedIndexChanged(object sender, EventArgs e)
    {
        bestückeAusgabeCards();
    }



private void bestückeAusgabeCards()
    {
        List<FREE.konzepte> listeDBfürDROPDOWN = new List<FREE.konzepte>();
        using (comidosDElocalEntities context = new comidosDElocalEntities())
        {
            listeDBfürDROPDOWN = context.konzepte.ToList();
        }
        foreach (var item in listeDBfürDROPDOWN)
        {
            if (item.kategorie_id.ToString() == ddKat.SelectedValue)
            {
                ausgabe.Controls.Add(erzeugeBlogEintragMasonry(item));
            }
        }
    }


    public static HtmlGenericControl erzeugeBlogEintragMasonry(konzepte konzeptItem)
    {
        // function body stays the same
    }

Is there a way to trigger the layout method of Masonry on a specific Event that fires when the update panel changes? Or is there another way to execute client-side code when the content of the output-div changes within the update panel?

Answer №1

After utilizing the UpdatePanel, all the contents within it get refreshed, resulting in a change in the DOM and the bindings applied to it. Therefore, it is necessary to execute jQuery again in order to recreate the Masonry layout.

Simply place this code snippet and it should function correctly.

<script>
    var prm = Sys.WebForms.PageRequestManager.getInstance();

    // Executed when the updatepanel finishes reloading
    prm.add_endRequest(function () {
        initMyMasonry();
    });

    // Executed during the initial page load
    initMyMasonry();

    function initMyMasonry() {
        // Create your masonry layout here
    }
</script>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Experiencing difficulties with retrieving form data in req.body using Express and node.js

I am facing an issue while trying to create a registration form for new users with profile picture upload. Despite adding body-parser middleware, the form data is not passing correctly to the route and I cannot identify the reason behind it. Error: D:&bso ...

Using 'if' conditions in Reactjs: A step-by-step guide

Working with Reactjs in the nextjs framework, I have received user data that includes the "category name (cat_name)" selected by the user. Now, I need to display that category in a dropdown menu. How can I achieve this? The current code snippet showcases ...

Is there a way to verify if both the username and email have already been registered?

I've exhausted multiple methods attempting to solve this issue, but every attempt falls short. My most recent strategy involved creating two "findOne" functions, however, even that proved unsuccessful. const checkUser = registerLogin.findOne ...

How can the dot badge in Material-UI be enlarged?

I'm in need of a badge component that serves as an indicator without displaying any values. I opted for the dot variant, but it's too small for my liking. I tried modifying it with CSS, but it doesn't seem to be working as expected. Any sugg ...

Ways to resolve issues related to null type checking in TypeScript

I am encountering an issue with a property that can be null in my code. Even though I check for the value not being null and being an array before adding a new value to it, the type checker still considers the value as potentially null. Can anyone shed lig ...

Creating an attractive image carousel using jQuery or YUI for your website

I am searching for a javascript-based slideshow solution for images. I have received the following requirements: The slideshow should fade one image into another, looping back to the first image after all images have been displayed It must include naviga ...

Having trouble binding component property in VueJS with TypeScript?

Why is my component property not binding when I set the related component attribute to a value? Even when inspecting with Vue devtools or outputting the value into the HTML, it remains at the default value set on the component. I tried setting a string at ...

refreshing datatables with updated data from a different endpoint

Need help reloading datatables with the new ajax feature? I suspect it might be a scope issue. function refreshTable(tableName, src) { var table = $('#'+tableName).DataTable({ 'bProcessing': true, 'bServerSide ...

three.js fur effect not appearing on screen

I have been working on understanding and implementing fur in three.js. I came across an example at which I used as a reference to comprehend the code. The model loads successfully, but the issue arises when the fur texture doesn't load. I have check ...

I'm looking for a way to retrieve an object from a select element using AngularJS. Can

I am working with a select HTML element that looks like this: <select required="" ng-model="studentGroup"> <option value="" selected="">--select group--</option> <option value="1">java 15-1</option> <option value="2">ja ...

Expanded MUI collapsible table squeezed into a single cell

I'm experimenting with using the MUI table along with Collapse to expand and collapse rows. However, I've noticed that when utilizing collapse, the expanded rows get squished into one cell. How can I adjust the alignment of the cells within the p ...

Transforming a detailed JSON structure into a more simplified format with Angular 2

As a newcomer to Angular 2, I find myself encountering a hurdle in filtering unnecessary data from a JSON object that is retrieved from a REST API. Below is an example of the JSON data I am working with: { "refDataId":{ "rdk":1, "refDataTy ...

The calculator I designed using HTML, CSS, and JavaScript is experiencing difficulty adjusting to various screen sizes

I recently built a calculator using HTML, CSS, and JavaScript. It works perfectly on PC or big screens, but when viewed on smaller devices like phones or tablets, the display gets cut off and does not adjust properly. Here are some example pictures for ref ...

The proper way to cancel useEffect's Async in TypeScript

I'm facing an issue with this straightforward example: useEffect(() => { axios.get(...).then(...).catch(...) }, [props.foo]) warning: can't perform a react state update on an unmounted component After some investigation, I found this ...

Maximizing Performance: Enhancing Nested For Loops in Angular with Typescript

Is there a way to optimize the iteration and comparisons in my nested loop? I'm looking to improve my logic by utilizing map, reduce, and filter to reduce the number of lines of code and loops. How can I achieve this? fill() { this.rolesPermiAdd = ...

Creating multi-dimensional arrays using array lists with Axios and Vue.js

My knowledge of axios and JavaScript is limited, and I find myself struggling with creating a multi-dimensional array. 1. This is how I want my data to be structured : https://i.stack.imgur.com/kboNU.png userList: [ { ...

What could be causing the React text input to constantly lose focus with every keystroke?

In my React project using Material-UI library, I have a component called GuestSignup with various input fields. const GuestSignup = (props: GuestSignupProps) => { // Component code goes here } The component receives input props defined by an ...

Exploring the global document object within Next.js

We have been working on a project using nextjs and are facing an issue with changing the styling of a button upon click. Despite using document.getElementById, we are unable to change the styling no matter what we try. pages/index.js function Index() { ...

Tips for initiating a browser file download using JavaScript, ensuring that the download is only carried out if the web service responds with

For a project I am working on, I need to create JavaScript code that will be triggered by clicking on an <a> element. This code will then make a GET request to a web service that I am currently in the process of coding. Once the service returns a fil ...

Struggling to understand the javascript snippet "requiring the passport file and passing in passport as a parameter."

I am still learning the ropes of javascript and currently working on a basic login restful api using the passport middleware. I understand that when I use require('xxxxx'); I am importing a module for use. While researching online, I came across ...