The JavaScript code is not functioning properly because of an internal script issue in ASP.NET

On my page, there is a div that displays a message with the span tag "x". When the user clicks on the x, the div hides. Initially, this functionality worked fine with the JavaScript code in an external script file. However, when I introduced some inline JavaScript on the page, the div stopped working. I even tried moving the inline script to an external file, but simply including the file name on the page caused the div to malfunction. Below is the code for my page, with the 'msgpanel' div that shows and hides.

<%@ Page Title="" Language="C#" MasterPageFile="~/mCSSv2.Master" AutoEventWireup="true"
    CodeBehind="WU_adddetails.aspx.cs" Inherits="mCSSv2.WU_adddetails" %>

  <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

  </asp:Content>

  <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script src="/js/popup.js"></script>

    <script src="/js/jquery.min.js"></script>
    <script src="/js/pasteimage.js"></script>
    <style type="text/css">
      #upload_image {
        width: 300px;
        height: 300px;
        background-color: #F5F6F7;
        border-radius: 10px;
        border: 2px solid #E5E5E5;
        text-align: center;
        margin: 15px;
      }
      
      // More CSS styles here

              <!-- Closing tags and more content -->
    </style>

          <div id="main-content">
              // More HTML content here

                    <div id="msgpanel" runat="server">
                      <asp:Literal ID="msg" runat="server" Visible="false"></asp:Literal>

                    </div>

                     // More HTML content here

                </div>

        </asp:Content>

Below is the snippet of JavaScript code from my script file that is responsible for hiding the div:

$(document).ready(function() {

  
  /*
   * Closable Alert Boxes
   */
  $('span.hide').click(function() {
    $(this).parent().slideUp();
  });

  (function($) {
    $.pasteimage(function(value) {
      $("#upload_image img").attr("src", value);
      // Additional logic here
    });
  })(jQuery);

Answer №1

Perhaps the asp.net rendering isn't quite working the way you intended. Try taking the following two steps:

  1. Add a class to the "msgpanel" div.

    div id="msgpanel" class="msDiv" runat="server"

  2. In your script, locate the div using this class and slide it up

    $('span.hide').click(function() {

      $('msDiv').slideUp();
    

    });

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

Implementing Pagination in Vue: How to Make it Work with Response Data

I am looking to integrate pagination from the response data into my existing code, while also incorporating filters. JavaScript var entriesList = new Vue({ el: "#post-list-template", data: { posts: [], categories: [], cu ...

Angular, JavaScript, and PHP are three powerful programming languages that

This file contains HTML code <ul class="list"> <li id="numword" data-score="{{item.score}}" class="" ng-repeat="item in words track by $index"> {{item.word}} {{item.score}} </li> </ul> Here is the visual representa ...

What techniques can I use to streamline the following?

var cleanWord = word .split(/[^a-z0-9\s.\|]/gi) .join("") .replace(/([~@#$%^&*()_+=`{}\[\]\\:;<>\/ ])+/g, ""); I suspect that I am redundantly using the join function twice here. Is there a way to ...

React state is not refreshing as expected

I am having trouble updating the state with new employee data. The push function is not inserting the new employee data into the state. In the addPar function, I set up a console log and it shows that the data is there, but it fails to push it to the sta ...

Switch the image back to its original source after a brief amount of time

Looking for help with a function that changes the source of an image after a two-second delay, then reverts it back to a different random image: function ChangeToBomb() { var aantalPionnenOpScherm = $('#depionnen img') var randomPion = M ...

Error is triggered by starting variable names with a leading number

I am creating a variable with a unique and dynamic name. var 8inuf3k9r2ggp914zey8hn6vgwky3aqalr4zi6a01yx4x8cdv4eqlby9i6a9v9j4 = pusher.subscribe('channel'); Encountering an error in Chrome: "Uncaught SyntaxError: Unexpected number". The root c ...

Storing data with just a click

Upon clicking the link <a href="http://localhost/redmine/projects/'+ value.id+'">'+ value.name+'</a>, I aim to store the value.id into the following variable: x is the variable. var x = document.getElementById(value.id).va ...

Having trouble parsing XML with JavaScript

I am currently attempting to parse an XML file using JavaScript for a school assignment, and I am required to use pure JavaScript without jQuery. I am able to retrieve one value successfully, but encountering issues with another. The problem lies within m ...

"Exploring the Functionality of Page Scrolling with

Utilizing Codeigniter / PHP along with this Bootstrap template. The template comes with a feature that allows for page scrolling on the homepage. I have a header.php template set up to display the main navigation across all pages. This is the code for th ...

What is the best way to eliminate the gap between inline-block elements?

I'm trying to make two inline-block divs with width: 50% each fit on one line. <div class="inline">Left one</div> <div class="inline">Right one</div> I know a practical solution, but I also want my code to look nice. <div ...

Unit testing setTimeout in a process.on callback using Jest in NodeJS

I've been struggling with unit testing a timer using Jest within my process.on('SIGTERM') callback, but it doesn't seem to be triggered. I have implemented jest.useFakeTimers() and while it does mock the setTimeout call to some extent, ...

Is there a way to transform a six-digit input into a date format using vue/JavaScript?

I've explored various solutions for this issue, but they all seem to be backend-focused. What I need is a Vue/JavaScript method. I have a string containing IDs, with the first 6 digits representing the date of birth and the final 4 digits being a pers ...

A guide to importing a Vue component in a JavaScript file

I am looking to achieve a specific behavior in my project: depending on a condition stored in my database, I want to load a particular vue.component instead of another. For example, within a file named discover.js, there is the following code: Vue.compone ...

What is the correct way to utilize JavaScript's clearTimeout function with arguments?

I came up with a simple function to mimic the movement of window blinds. It runs on a server that receives requests with a direction parameter determining whether the blind should move UP, DOWN, or STOP. The simulation works like this: upon receiving a re ...

Scrolling with jQuery to create a fixed navigation bar

I'm having an issue with my navbar on my website. I used CSS and jQuery to keep it fixed at the top, but now when I click on a menu item, it doesn't scroll to that section of the page. Can anyone help me troubleshoot this problem? ...

jquery is failing to recognize the HTML generated by ajax

Upon successful login, the website displays a button with the HTML code below: <button class="logout-button">Logout</button> The button is also hardcoded into the website's HTML for consistency. However, after refreshing the page, the AJ ...

Showing a Null value from a database using asp.net

I need help with displaying information from my database in asp.net. Some values are null and when I try to load them on the page, it causes an error. How can I resolve this issue? I want to display everything from the database, regardless of whether it is ...

Most effective method for adjusting image size to match div container (as background)

I'm attempting to create a background with 85% height and 100% width on the index page using Bootstrap 4. However, when I set an image as the background in a div, it doesn't resize correctly and only shows a portion of the image (as the image is ...

I'm encountering a 400 error when using xsr.send within my AJAX request in a .NET Core application

I encountered an error 400 while attempting to make an Ajax call in .NET core 2.0 with entity framework using jQuery 2.2. This is how my Controller Method is structured: [HttpPost] [ValidateAntiForgeryToken] public JsonResult RetrieveDateCollectio ...

What is the process for updating IDs and names for duplicated elements?

I have created a select box and used the clone function to generate dynamic select boxes. However, the cloned select boxes have the same ids and names as the original. How can I change the ids and names of the cloned elements in my code sample below: < ...