Issues with Javascript code syntax

I have encountered an issue while creating a new literal control from code behind. I am able to add standard HTML into it successfully, however, when I try to insert <%= SomeDiv.ClientID %> into the literal control, it simply prints exactly what is in the code behind.

Code behind:

new LiteralControl("<div id='" + paneID.Replace(" ", "") + "_Expand' runat='server' onclick='ChangePanelHeader(&#39;<%= " + paneID.Replace(" ", "") + "_Expand.ClientID %>&#39;" + ", " + "&#39;<%= " + paneID.Replace(" ", "") + "_cpe.ClientID %>&#39;)' class='rhsCollapsiblePanelsHeader'>" + paneTitle + "<br /><br /></div>" + paneContent)

Upon page load, in Browser Source:

<div id='Tellafriend_Expand' runat='server' onclick='ChangePanelHeader(&#39;<%= Tellafriend_Expand.ClientID %>&#39;, &#39;<%= Tellafriend_cpe.ClientID %>&#39;)' class='rhsCollapsiblePanelsHeader'>Tell a friend<br /><br /></div>

Desired output:

<div id='Tellafriend_Expand' runat='server' onclick='ChangePanelHeader("MyTelAFriendID_Expand", "MyTelAFriendID_cpe") class='rhsCollapsiblePanelsHeader'>Tell a friend<br /><br /></div>

Error message in Firefox:

syntax error
[Break On This Error]   

ChangePanelHeader(<%= Tellafriend_Expand.ClientID %>, <%= Tellafriend_cpe.Cli...

default.aspx (line 1, col 20)

Answer №1

When I first read this, I had a moment of confusion. It seems like the server-side code is outputting ids without being enclosed in quotes. In JavaScript, these ids should be treated as strings. Here's a suggestion:

ChangePanelHeader("<%= Tellafriend_Expand.ClientID %>", ...);
// make sure to include quotes ----^----------------------------------^

If this doesn't solve the issue, I'll patiently wait for the revised question mentioned in your comment.

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

Transform a 3D text rotation JavaScript file into an Angular component tailored TypeScript file

I have a javascript file that rotates text in 3D format, and I need help converting it into an Angular component specific TypeScript file. You can find the codepen for the original JavaScript code here. Below are my Angular files: index.html <!doctyp ...

What is the best way to place a 3D model at random points on the surface of a sphere while ensuring that it always faces the right direction?

I'm faced with the challenge of placing huts randomly on a spherical world. While this task is feasible, the issue arises when the huts do not sit correctly - their bottom should be in contact with the tile below. I've experimented with the &apos ...

What is the best way to rerun a script without having to manually refresh the entire webpage?

If you visit greenb.byethost12.com, you can check out the progress I've made so far. Currently, when you click on the correct answer, it triggers document.location.reload(index.php), causing the entire page to refresh. What I aim for is to have only ...

Ensure that the HTML link is valid and authenticated using SESSIONS

When creating a website, one of the initial tasks I like to tackle is adding links at the bottom of the page for checking valid HTML and CSS: HTML5  •   CSS <div> <a href="http://validator.w3.org/check?uri=referer" ...

Oops! There seems to be a problem with the Node.js App. The MongooseError is indicating that the parameter `uri` in the `openUri()` function should be a string,

I've encountered an issue with my Next.js app involving MongoDB that I've been struggling to resolve. Hoping someone here can provide some insight and help me out. This is quite crucial for my project. First, I'll share the code from my serv ...

The issue of Storybook webpack failing to load SCSS files persists

I'm running into an issue where my styles are not loading in Storybook, even though I'm not getting any errors. Can someone help me out? My setup involves webpack 2.2.1. I've scoured Stack Overflow and GitHub for solutions, but nothing seem ...

Extracting names from HTML can be done easily by looking for the "@" symbol that the

My HTML structure looks like this: <table id="table-15244" cellspacing="0" class="comment"><tbody> <tr id="comment-37"> <td style="color: #999" class="NV"> </td> <td class="hidden-mob"> ...

What is the functionality of Vue plugins in Vite MPAs?

I have developed a Vite application and I am trying to implement multiple pages. I followed the documentation on how to achieve this (link here), but when I start the server, all I see is a blank page. This is what my vite.config.js file looks like: impor ...

Enhancing AngularJS view rendering using ngshow

Currently, I am working on a view where ng-show is used to display a select DOM object when certain conditions are met, and an input DOM for all other scenarios. However, I have noticed that there is a significant delay in the disappearance of the input bo ...

What is the process of saving a model with @tensorflow/tfjs-node version 2?

I've been struggling with setting up the save handler to save my model. I've scoured through various platforms like stack overflow and GitHub, but haven't had any luck. Help! Any guidance would be greatly appreciated!!! :) Below is a snipp ...

Retrieve data with a web API

I am currently developing a web API to fetch data from a mock database using express My goal is to retrieve a JSON list containing all portfolios and their corresponding positions from the database module. Is there a way to structure the returned data so ...

add the AJAX response to the specified div element

I'm currently using an ajax call to retrieve movie data from the IMDb API for 'The Shawshank Redemption'. My goal is to display this data within the designated div element. <div id="movie-data"></div> Here's my current Jav ...

Having difficulty showing the successful JSON output in either the view or an alert

In my CodeIgniter project, I have three input fields named name, emp_id, and crm_id. I enter the id value and send it to the controller via AJAX and JSON to retrieve all information related to that id. The issue is that while I can see the correct output i ...

Ran into a JavaScript heap memory issue while attempting to perform an npm install on Azure pipeline

Currently in the process of updating my angular projects from angular 16 to angular 17. When running npm install, everything runs smoothly with angular 17 on my personal laptop. However, when attempting the same process on Azure pipeline, I encounter an er ...

Client component in Next.js is automatically updated upon successful login

I am currently working on a Next.js + DRF website that requires authentication. I have set up my navbar to display either a "log in" or "log out" button based on a boolean prop passed from the server side to the client-side: export default async function R ...

Searching through an array for multiple values on the same key

I am currently working on dynamically generating a listview in jQuery. So far, I have been successful in creating the entire list dynamically. However, I now face the challenge of filtering, searching, or reducing my initial data: var recipes = [ { "name" ...

Utilizing jQuery for AJAX requests on a timed loop

I'm puzzled by a situation involving an AJAX call within an interval. It seems that the code doesn't work as expected, and I'm wondering why. Initially, I had this code snippet which wasn't functioning properly: setInterval($.ajax({ ...

The scrolling behavior varies in Firefox when using the mouse wheel

Currently, I am working on a website where I want to display large text on the screen and have the ability to scroll two divs simultaneously. This functionality is already in place. I can scroll the divs, but I'm facing an issue with the jumps being t ...

Neither req.body nor req.file contain any data

Hey everyone, I'm new to coding and currently working on creating a basic markdown blog. However, I'm facing an issue where req.body doesn't contain my markdown field and req.file is undefined when trying to upload an article. I'm unsur ...

Securing HTML pages with ASP.NET MVC authentication

Within my MVC application, there are a few static (pure html) pages that require authentication to prevent unauthorized access. Is there a method to achieve this without transferring all the code to asp files and incorporating a controller, which would t ...