The dynamic creation of CSS and JavaScript file references within a user control and placed in a placeholder

I designed a custom user control featuring a single image. I am dynamically generating the user control within a placeholder on the web form.

Within the user control, I included references to CSS and JavaScript files, but they are not affecting the appearance of the image.

NOTE: The image is still displayed on the web form.

Here is the code for the user control:

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="IVT_DisplayImage.ascx.cs" Inherits="Sublayout_IVT_DisplayImage" %>

<link href="~/css/demo.css" rel="stylesheet" type="text/css" />
<link href="~/css/imagezoom/imagezoom.css" rel="stylesheet" type="text/css"
/>
<script src="~/js/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="~/js/jquery.imagezoom.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#imgIdCard').ImageZoom();
    });
</script>
<div class="page">
    <div class="box cf">
        <div class="left"> <span class="demowrap">
                        <asp:Image ID="imgIdCard" runat="server" />
                    </span>

        </div>
    </div>
</div>

Here is the code for the web form:

<div>
    <asp:placeholder ID="plhDisplayImage" runat="server"></asp:placeholder>
</div>

This is the code behind for the web form:

Sublayout_IVT_DisplayImage ivtDisplayImage = new Sublayout_IVT_DisplayImage();


protected void Page_Load(object sender, EventArgs e) {
    ivtDisplayImage = (Sublayout_IVT_DisplayImage) LoadControl("~/Sublayout/IVT_DisplayImage.ascx");
    ivtDisplayImage.ImageURL = "~/demo_assets/large/1.jpg";
    plhDisplayImage.Controls.Add(ivtDisplayImage);
}

And here is how the folders are structured:

css/
    demo.css
css/imagezoom/  
    imagezoom.css
js/
    jquery-1.8.3.min.js
    jquery.imagezoom.min.js
Sublayout/
    IVT_DisplayImage.ascx
Root:
    Default.aspx

Answer №1

It seems like the problem lies with the path, try removing the ~ from the paths in the user control. Edit: consider replacing the ~ with ..

Edit: I noticed that you are targeting the image by ID, but since it's a runat="server" control, it will have a different rendered ID (as seen in your HTML).

To target the image by ID using JQuery, you'll need to resolve the Client Id (there are many resources on how to do this), but CSS won't be able to do this.

Instead: assign a class to the image and target it using the class selector (in JQuery and CSS). This is the simplest approach.

Final Solution (provided by the owner): By adding references in the web form and removing them from the user control, everything works smoothly now. Thank you for your assistance, it turns out the ID was indeed causing the issue.

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

Centralizing images in a Facebook gallery/lightbox during the loading process

Is the image width and height stored in Facebook's gallery database? In typical JavaScript usage, the image width and height cannot be determined until the image is fully loaded. However, on Facebook, images are pre-loaded before being displayed, ens ...

The drop-down menu selection is non-functional on mobile and iPad devices when using Bootstrap

<div class="panel panel-default"> <select> <option value="B3">B3</option> <option value="B4">B4</option> <option value="B5">B5</option> & ...

Tips for allowing a position:absolute <div> to expand as though it were containing a lengthy <p>innerText

This div automatically adjusts its width to fit the content inside, even if it extends beyond the page boundaries. Is there a way to make this div expand to fill the entire width of the page without needing a paragraph? <div style="position:absolute;le ...

The issue of AJAX not functioning on multiple forms on a single page

i have implemented two separate ajax scripts. The first script is for the login functionality. $(document).ready(function() { $("#ajaxform").submit(function(e) { $("#simple-msg").html("<img src='loading.gif'/>"); var postData =""; ...

Inability of Internet Explorer 10 to load resource files

As I work on constructing a website using a combination of HTML5, CSS3, and jQuery, I have encountered an issue when trying to view the page in Internet Explorer X. Despite my efforts to troubleshoot by clearing the cache and adjusting security settings, t ...

Combining various postponed JavaScript file imports in the HTML header into a single group

I've been facing an issue with my code structure, particularly with the duplication of header script imports in multiple places. Every time I need to add a new script, I find myself manually inserting <script type="text/javascript" src=&q ...

Trouble with Select2 delay function not functioning

I've implemented the following code to set up select2 on a select box. However, the delay feature doesn't seem to be working as expected as requests are being sent to the server immediately. $(".multi_select").select2({ multiple: true, a ...

Tips for concealing a div upon reaching a specific scroll point, even with varying content sizes

Hey there! I am completely new to web programming and currently working on a landing page. The challenge I'm facing is that the content in the first column is dynamic, meaning it can vary in length. I'm looking for a way to hide my call-to-actio ...

Looking for the optimal width ranges for media queries on laptops and cell phones?

Can anyone suggest the optimal width parameters to use in my code for different screen sizes, from tablets and laptops to cellphones, in order to create a responsive design? ...

Smooth Slide-in Animation

I've been working on improving my understanding of animations, but keyframes are still a bit confusing for me. To help with my learning process, I decided to create a simple box slider that fades in each layer and then repeats the process. My goal is ...

Is there a way to keep the header frozen while loading page content during postback?

Currently, I am working with asp.net and c#.net to develop a website. My goal is to create a content navigation system similar to what Microsoft has implemented on their Windows website: Microsoft Windows On this link, users can navigate through page cont ...

Is it possible to create a mouse-following effect with lighting using Javascript

Recently, I've been honing my Javascript skills and decided to create a follow-mouse function. After successfully implementing it, I started brainstorming a new concept that I'm unsure is achievable. Is there a way to develop an "orb of vision" ...

Button Element Not Appearing in JavaScript/HTML

My current project involves creating a replication of the Windows calculator to practice JQuery and JavaScript. I have already set up all the HTML buttons for this basic calculator, but I am facing an issue where only the number "1" is displayed when click ...

What could be causing the server to return an empty response to an ajax HTTP POST request?

Attempting to make a POST request using ajax in the following manner: $.ajax({ type: "POST", url: 'http://192.168.1.140/', data: "{}", dataType: "json", ...

Combine and interchange horizontal and vertical form designs within antd 5 for a personalized touch

I need to customize the layout of a form to display checkboxes in vertical mode. Specifically, there is a row of checkboxes that I want to appear vertically aligned rather than horizontally. In the past, I was able to achieve this in antd 4 by applying a ...

Executing a personalized function - settings.func does not exist as a valid function

I have developed a custom jQuery plugin where I intend to invoke a specific function like this... (function($) { $.fn.customPlugin= function(options) { var settings = { func: null }; if (options) { $. ...

How to horizontally center a div with margin using CSS

Is there a way to horizontally center a div with margins using CSS? <div id="container"> <div id="center_me"></div> </div> #container{ position:relative; width:100%; height:400px; } #center_me{ position:absol ...

Using the post method to send JSON data and retrieving it in an ASPX file

Hey there! I'm currently working on integrating jQuery AJAX to send data to my aspx file. Below is the code snippet for my AJAX request: $(document).ready(function() { $('#openmodal').click(function() { var id = $(this).attr(&ap ...

Can uniform columns be created in separate HTML elements?

Looking to create a uniform list in HTML, where the columns inside each panel line up perfectly. See the desired layout: https://i.sstatic.net/FbbPu.png In this example, Col_1 has a width of "BBBBB", as it is the widest content in that column, ...

Problem encountered when trying to apply background opacity to custom colors using Tailwind CSS and shadcn/ui

While using Tailwind CSS along with the shadcn/ui library for styling buttons, I have encountered an unexpected behavior. The issue arises when trying to add background opacity to a custom color defined in globals.css using HSL values such as: --primary: 3 ...