What could be causing the CSS to malfunction when the dropdownlist is updated without refreshing the page?

Currently, I have implemented DropKick CSS/JQuery to customize the appearance of my asp:DropDownList:

<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
    <ContentTemplate>
        <asp:DropDownList AutoPostBack="True" OnSelectedIndexChanged="ddlMain_SelectedIndexChanged" ClientIDMode="Static" ID="ddlMain" style="width: 365px;" class="default" runat="server" AppendDataBoundItems="true">
        <asp:ListItem Text="BY PHYSICIAN" Value="0" Selected="True" />
        <asp:ListItem Text="BY LOCATION" Value="1" />
        <asp:ListItem Text="BY SPECIALTY" Value="2" />
        </asp:DropDownList>
        <br /><br />
        <asp:DropDownList ClientIDMode="Static" ID="ddlDrillDown" style="width: 365px;" class="default" runat="server" AppendDataBoundItems="true">
        </asp:DropDownList>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="ddlMain" />
    </Triggers>
</asp:UpdatePanel>

Upon initial page load, the layout appears as shown below:

I have configured the UpdatePanel, Trigger, and ScriptManager control to ensure that changes made in ddlMain are reflected in ddlDrillDown without requiring a page reload. After overcoming some challenges, I noticed that when selecting a different option in ddlMain, the DropKick style vanishes:

The developer console displays the following on page load:

<div id="dk_container_ddlMain" class="dk_container dk_theme_default default" aria-hidden="true" tabindex="0" style="margin: 0 auto; display: inline-block;">

    <a class="dk_toggle dk_label" style="padding: 10px; color: rgb(43, 71, 125); width: 365px;">

        BY PHYSICIAN

    </a>
    <div class="dk_options">
        <ul class="dk_options_inner" aria-hidden="true" role="main">
            <li>
                <a data-dk-dropdown-value="0" style="padding: 20px; color: #2B477D">

                    BY PHYSICIAN

                </a>
            </li>
            <li>
                <a data-dk-dropdown-value="1" style="padding: 20px; color: #2B477D">

                    BY LOCATION

                </a>
            </li>
            <li>
                <a data-dk-dropdown-value="2" style="padding: 20px; color: #2B477D">

                    BY SPECIALTY

                </a>
            </li>
        </ul>
    </div>
    <select id="ddlMain" class="default" style="width: 365px;" onchange="javascript:setTimeout('__doPostBack(\'ctl00$FeaturedContent$ddlMain\',\'\')', 0)" name="ctl00$FeaturedContent$ddlMain">
        <option value="0" selected="selected">

            BY PHYSICIAN

        </option>
        <option value="1">

            BY LOCATION

        </option>
        <option value="2">

            BY SPECIALTY

        </option>
    </select>

</div>

Each time a different option is selected, the developer console presents this output:

<select id="ddlMain" class="default" style="width: 365px;" onchange="javascript:setTimeout('__doPostBack(\'ctl00$FeaturedContent$ddlMain\',\'\')', 0)" name="ctl00$FeaturedContent$ddlMain">

    <option value="0">

        BY PHYSICIAN

    </option>
    <option value="1" selected="selected">

        BY LOCATION

    </option>
    <option value="2">

        BY SPECIALTY

    </option>

</select>

This behavior suggests that the originally assigned styling is lost upon selection of a new option.

Is there any way to preserve the styling without refreshing the page?

It seems that the style remains intact if the page refreshes after each selection.

The provided script styles the dropdown on load:

<script type="text/javascript">
    $(document).ready(function(){

        $('.default').dropkick();
    });
</script>

Answer №1

When utilizing a jQuery plugin within an UpdatePanel, it's essential to re-instantiate the plugin after every postback occurs. To do this, simply reinitialize the plugin in the Ajax pageLoad function like so:

function pageLoad(sender, args) { //re-initialize the plugin here }

UPDATE: My apologies...It seems that MightLampshade made a similar point before me while I was still typing my response.

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

How can you set a default page based on a specific condition in ASP.NET MVC?

I have a custom class named PasswordChangeChecker.cs that contains a method to check if a user has changed their password in the database. The method signature is as follows: public bool IsPasswordChangedFromInitial(string IdOfUser) The input parameter I ...

Updating a .doc file using ASP.NET

Seeking assistance in the ASP.NET project to locate code that can read, adjust the font, and save the DOC file. Is there any code available to edit a DOC file format? ...

Prevent the transfer of data from webpage

Is there a way to prevent users from copying content on a web page? I want to ensure that no text can be selected by the user. I am currently working on asp.net and would appreciate any creative ideas or solutions. ...

Loop through the array of request identifiers in PHP

function LoadProtocols(){ ?> <?php $result=mysql_query("SELECT id,name,Destination_port, Destination_port_range_start, Destination_port_range_stop FROM protocols;"); echo '<table class="tftable" border="1">'; ech ...

Is it possible to create tabs using Ajax without using jQuery?

Exploring the realm of tabs that dynamically load content into a div without redirecting to another page unveils numerous possibilities. Although the existing examples mostly rely on ajax with jQuery or similar libraries, I am inclined towards exploring a ...

Identifying issues in jQuery code - What could be causing this error?

My jQuery code is not responding at all, not even showing an error! I'm not sure why, but here is the jQuery Code I'm using: /* This part is working fine */ $(".add-blog .blog-add-form .add-article .input-group select").on("change", function() ...

Optimizing Image Size According to the Container, Not the Screen Size: A Guide

After exploring various resources on responsive images, I have come across a challenge that has me stumped. It seems like it should be simple, but I can't quite figure it out: How can I serve the appropriate image size based on container width rather ...

Error: Bizarre ValidateInputIfRequiredByConfig anomaly

Recently encountered a random exception related to ValidateInputIfRequiredByConfig(). Unfortunately, the error message is in Portuguese due to our server settings. Although this error is typically caused by malicious input, that doesn't seem to be t ...

I am encountering difficulties displaying the image and CSS files from another folder in my HTML with Node.js

I am facing difficulty in establishing a connection between my front-end and back-end using node.js. As a result, the website only displays the HTML code without linking to the CSS or image files. Here is the folder structure: root -src •pi ...

Windowing box inside a container box

I am looking to implement scrolling for just the "chat-messages" div within the "chat-bar" div on my site. I want only this specific section to be scrollable, while the rest of the site remains stationary. Currently, I have to scroll through the entire pag ...

Can the vacant space on an HTML page be determined through calculation?

Could someone please help me figure out the amount of empty space on a html page? https://i.sstatic.net/VXzbz.png Is it possible to determine the area highlighted in red using javascript? Apologies if this question seems trivial. ...

What is the best way to reset the selected option in Vue.js when clicking on a (x) button?

Is there a way to create a function or button specifically for clearing select option fields? I attempted using <input type="reset" value="x" /> However, when I clear one field, all fields end up getting cleared. Should I provide my code that incl ...

Chrome is opting to download PDF files rather than display them in the

For the past 3-4 years, I have had this code successfully running in production using Vue.js. <object :data="pdfUrl" type="application/pdf" width="100%" height="100%" style="min-height: 700px"> </object> When clicking a button, ...

Triggering click events for multiple items in a loop using jQuery

I'm struggling to make a jQuery click function work for all items generated by a PHP while loop. Currently, it only works on the first iteration. I want to trigger a popup window to show a message to the user when they activate the click function. P ...

Positioning Elements with CSS Relative and Absolute Placement

I am relatively new to the world of web design and currently grappling with the concept of positioning in CSS. I have a basic understanding of relative and absolute positioning for elements. In the code snippet below, there is a <div> that acts as th ...

What is the most suitable gridview event for inserting items into the dropdownlist utilized in the edit template?

When editing a gridview, I want to display different values in a dropdownlist based on the logged-in user. For example... The officer will see "Approved by Officer" status. The director will see "Approved by Director" status I am attempting to dynamicall ...

The alignment of the icon to the center of a div is disrupted when using bootstrap.css

Take a look at this code To center the icon within a div, I am using the following code: <div class="webview-back icon" style="width: 34px; height: 34px; display: inline-block; text-align: center; background-color: lightgray;"><i class= ...

Automated code generation and validation in Entity Frameworks

Currently, I am in the process of learning Entity Framework. Although I have a database, it is not yet complete. As I continue to add fields to my database and model in the future, Entity Framework updates the class code accordingly. However, there is an i ...

Retrieve information from SqlDataSource or GridView

I am working with a SqlDataSource and a GridView on my web form. I have set the GridView.DataSourceID to be mySqlDataSource. After calling myGridView.DataBind(), all the data successfully binds on the page. I am now looking for a way to read the data alr ...

What are the steps to set up the ionic framework on my Windows 7 system?

I am looking to set up the Ionic framework on my Windows system. However, I encountered an error while trying to install it. The warning 1909 appeared stating that it could not create a shortcut for node.js command prompt.ink. It asked me to verify if th ...