How to properly escape a double quote in the `eval` function

I am facing an issue with a link button in a gridview as shown below

<asp:LinkButton ID="lbtnEdit" runat="server" OnClientClick='<%# String.Format("Edit(\"{0}\", \"{1}\");return false;",Eval("Comment").ToString(),Eval("Status")) %>' >Edit</asp:LinkButton>

Everything works fine except when there are double quotes in the comment field. I tried changing it to Eval("Comment").ToString().Replace(/'/g, "\'") but unfortunately I received an error stating "The server tag is not well formed."

If anyone has any suggestions or solutions for this issue, please let me know.

Answer №1

The substitution you attempted employs JavaScript. Due to the presence of embedded quotes on the HTML page, JavaScript no longer considers it as a complete string. To rectify this issue, utilize the .NET adaptation of the replacement function to encode the data on the server side:

For Visual Basic (VB), here is an example:

Eval("Comment").ToString().Replace("""", "\""")

This code snippet will substitute all quotation marks within the comment with escaped equivalents, preventing any unintended closure or initiation of new strings.

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

Bootstrap 4 Alert: The collapse feature is currently in transition

Is there anyone out there who can assist me with solving a transition issue in Bootstrap 4? I am encountering the error message "Uncaught Error: Collapse is transitioning" when I don't include the bootstrap CSS. Unfortunately, including the bootstrap ...

Is there a way to convert an Office Word document into an image using VB.net

Is there a free and easy way to convert a Word document into an image file? I need to do this so that I can use iTextSharp to ultimately convert the image into a PDF. Any suggestions are greatly appreciated. Thank you! ...

Can I use leaflet to customize the types of roads displayed on the map?

Is there a way to customize the types of roads displayed at different zoom levels using data from the OSM highways list? I have checked the Leaflet documentation but couldn't find the answer. If you happen to come across it, please share the link. e ...

Synching the Angular controller with the view

I am having difficulty connecting the angular controller 'pointofsaleController' to a view (index.cshtml). Can someone assist me in identifying my mistake? This is in an MVC project created using visual studio. pointofsaleController.js (func ...

What is the method for viewing the content within div tags on an apex page?

Locationbox is a system outside of Salesforce, similar to Google Maps. An example can be viewed here; I am aiming to integrate it into the Salesforce platform. The first script tag fetches JavaScript code from the Locationbox service. Once the startup() f ...

Dynamic Input Rows in ASP.NET are a versatile feature that allows users to

My ASP.NET web application form requires users to input various details, including: Subject Code Subject Name Subject Details ....etc I want to make it easy for users by allowing them to click on a plus (+) or add button that will create ...

CSS :contains selector after adding a script through Ajax append operation

Is there a way to change the text color in $('td:contains("text")').css('color','red') after an Ajax load script? Here is the main code snippet <div id="datatable"></div> <script src="https://code.jquery.com/j ...

Link HTMLMediaElement with Android's playback controls

For my HTML/Javascript audio player that supports playlists, I have implemented a feature where the ended event automatically plays the next media in line. Everything works smoothly when using the player on Android Bromite browser, including the playback c ...

The date format adjustments vary depending on the web browser being used

I have a JavaScript function that displays the date in the browser, but the format changes depending on the browser. For example, when I open my project in Chrome, the format is 4/30/2015, but when I open it in IE, it's displayed as 30 April, 2015. Ho ...

Issues are arising with Jquery Scripts when running through Selenium in IE 9, resulting in the error message SCRIPT5009: '$' is undefined. However, these scripts are functioning correctly when executed directly in the web browser

While using Selenium, the code below is causing issues as it is not functioning properly. An error SCRIPT5009: '$' is undefined is being thrown in IE 9. However, if the code is executed in a web browser console after removing the "\" sign, i ...

Generating identical circles using PointsMaterial and CircleGeometry

My goal is to generate circles using two different methods: By utilizing a circle sprite and drawing it with Points and PointsMaterial Using basic circle buffer geometries Unfortunately, I am facing challenges trying to align them due to the size discrep ...

Tips for improving the efficiency of your search feature

In my React class component, I have implemented a search function that works well most of the time but can become very slow on certain occasions. The search functionality is triggered by onChange when there is an input change. The state "bigData" that is b ...

Utilizing dynamic, MongoDB-inspired expressions to eliminate specific elements from an array

In the process of creating a lightweight database similar to MongoDB, I am incorporating an object-oriented query language where references can be functions or object references: foo.users.find( args ); foo.users.remove( args ); The 'args' para ...

The search feature on mobile devices is currently malfunctioning

The jQuery code below is used to search for products. It works perfectly in desktop view, but the responsive mobile view does not seem to be functioning correctly. Can someone assist me with fixing this issue? $("#search-criteria").keyup(function() { ...

Cypress encounters a SyntaxError while running in continuous integration due to an unexpected token 'export' with the cypress-io/github-action@v2 typescript

Within my cypress plugin file located at frontend/cypress/plugins/index.ts, I have the following code snippet: export default ((on, config) => { // `on` is used to hook into various events Cypress emits // `config` is the resolved Cypress config }) ...

The unexpected presence of right-to-left (RTL) alignment in Material UI has completely

I meticulously set up my rtl configuration in v5mui with the following: emotion as styled-engine stylis v4 stylis-plugin-rtl v2 Everything seems to be working fine, but when I use certain complex components, my app's appearance crashes. There is a w ...

What is the best approach for capturing and managing a 406 error in VUEJS?

I am encountering a situation where I send the day and time to the API in order to verify if there is an opening in the schedule stored in the database. If no opening is found, the API responds with a 406 error code. As a result, I am seeing a 406 error ...

Error: The res.end function is not recognized within the passport npm package

Help Needed: I am encountering this error and unable to resolve it. Can someone please check it out? TypeError: res.end is not a function at allFailed (C:\Users\sam\OneDrive\desktop\WebDevPractice\secret-files\node_mo ...

Getting the text from an HTML input field requires accessing the value property of the

My goal is to generate a pdf report using php. The user will enter their name in an input box, which will then be passed to the second php page that searches the mysql database. Issue: When the user inputs their name, attempting to retrieve the data (var ...

Is it a wise decision to provide the client with a new token just one minute before the expiration of the old one?

When monitoring my backend, I constantly check the remaining time before the JWT expires, which is set to 15 minutes. If there is only one minute left or less, I generate a new JWT and include it in the response header as a setToken. The front-end can then ...