Executing a JavaScript function in C#

I am working on a project where I need to store form details and trigger a popup box when the submit button is clicked. To achieve this, I used try { } finally { }. However, I am unsure of how to link the popup box function in JavaScript to the C# file.

Below is the code snippet for JavaScript:

<script>
function xpopup() {
    document.getElementById("x").onclick = function () 
    {
        var overlay = document.getElementById("overLay");
        var popup = document.getElementById("xPopup");
        overlay.style.display = "block";
        popup.style.display = "block";
    }
}
</script>

And here is the code snippet for C#:

try { }
finally
{
    ScriptManager.RegisterClientScriptBlock(this, GetType(), "none", "<script>function xpopup();</script>", false);
}

Answer №1

To streamline the code, eliminate the <script> tag and the function keyword since the function has already been defined:

ScriptManager.RegisterClientScriptBlock(this, GetType(), "none", "xpopup();", false);

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

Issue with VueJS on Internet Explorer version 11 - SCRIPT1004 error: Missing semicolon

Internet Explorer 11 Error: SCRIPT1004: Expected ';' Hello there! My website is functioning properly on all browsers except for Internet Explorer. Below is the content of my babel.config.js file: module.exports = { presets: [ ['@vue ...

Unable to locate the JSON file for loading in ThreeJS

I am currently attempting to load an external model from Blender onto an Angular app using Three.js. I have been following a tutorial for guidance, found here. However, I have encountered an issue when trying to load the external file: loader.load('. ...

Tips for applying CSS styles to the active page link

Check out the code below: Is there a way to assign a specific class to the current page link so that the mouse cursor will display as default rather than changing to a hand icon? I'm looking for a solution where I can apply a class to the active lis ...

Create a log of events on a distant system using designated login information

I am in search of a solution to log events on a remote machine with specific credentials. This is essential for auditing the usage of my application within the domain, where the application performs server tasks and can be run from any PC within the domain ...

Retrieve a specific HTML fragment from an HTML document using the Html Agility Pack

Is there a way to extract an html "fragment" using the html agility pack from a full html document? In this case, I define an html "fragment" as all content enclosed within the <body> tags. For instance: Input Sample: <html> <head> ...

React isn't updating the content within the div

Experimenting with basic React apps and attempting to run React. The index.ejs file contains a div tag that holds the content. Initially, I set the content to '...' in my server.js file. However, when adding React code in the index.js file locate ...

What is the reason for the Client Height value not affecting other elements?

I'm trying to set the spacing of my sidebar from the top equal to the height of the header. However, when I use clientHeight in JavaScript to get the height and then try to apply it to other elements using marginTop or top values (with position includ ...

Converting JavaScript arrays to PNG images on the client side

Is it possible to transform a 2d array of hexadecimal codes into a PNG image? The arrays are structured like this (but larger in scale) [   [     '#FF0000',     '#00FF00'  ],   [     '#0000FF',     '#000000&a ...

How can I modify the material and color of the result in Three.js CSG?

Upon creating a union of two meshes, I want to apply MeshLambertMaterial specifically on the object named 'result': var lathe = new THREE.Mesh(latheGeometry); var cube_bsp = new ThreeBSP( lathe ); var box = new THREE.BoxGeometry( 2,30,3); var ...

Can anyone provide guidance on how to calculate the total sum of a JavaScript array within an asynchronous function?

Currently, I am working with Angularjs Protractor for end-to-end testing and faced an issue while trying to calculate the sum of values in a column. Although I am able to print out each value within the loop successfully, I am struggling to figure out ho ...

"Learn how to implement a feature that allows for the acceptance of string input in discord

I am struggling to find the right solution for my issue. I am trying to implement a change_nick command but unsure about what type/number option to utilize. This is how I'm creating my command: commands.create ( { ...

Having trouble generating the Sencha Touch 2 jsb3 file, encountering a TypeError with 'undefined'?

Trying to configure and launch a Sencha Touch 2 application. Currently, I am following the instructions detailed in this guide: Upon executing sencha create jsb, I encountered the following error message: TypeError: 'undefined' is not a functio ...

Where should the logic for the Redux app be implemented for optimal performance?

My react-redux app features an action-creator that filters a list of objects based on a specified title: export const filterItems = (title) => dispatch => { axios.get(`/api/items/?title=${title}`) .then(res => { dispatch({ ...

Running a CSS keyframes animation can be achieved by removing the class associated with it

Is there a way to reverse the CSS animation when a class is removed? I'm trying to achieve this on my simple example here: https://codepen.io/MichaelRydl/pen/MWPvxex - How can I make the animation play in reverse when clicking the button that removes ...

HTML5Up! Skyrocketing with Meteor showers

While attempting to utilize a responsive site template from , I encountered several issues. To test the template, I downloaded the Striped package and created a clients folder in a Meteorite app where I placed the Striped folder. In order to make it work, ...

Establishing a session in C#

Hello, I am currently working on developing a login form in C# from scratch using a 3-tier architecture. I have successfully created a functioning form that validates user data input. If incorrect data is entered, an error message is displayed. Now, my nex ...

initiating an event within a modal controller

I have a $scope.$on callback function in my mainController. It works perfectly whenever I call it from each controller, but when I call it from a modalController after opening the modal, it doesn't work: define(['app', 'jquery'], ...

Unleashing the Power of JavaScript to Boost Page Performance

I've created a page using Vue.js 2 and Jquery, but it's running very slowly. I'm really struggling to optimize its performance. Could any experts out there help me with some ideas on how to speed it up? Thank you in advance. Here is the lin ...

How can I transform an array of text into dropdown options?

Currently, while utilizing Vue and vue-bootstrap, I am facing the task of populating a dropdown menu with an array of text items retrieved from my database. The <b-form-select> component in Bootstrap requires objects of the form {value: 'some va ...

Confirm the date's validity and then proceed to compare it with

In my ASP.NET 4.0 project, I have developed a web user control for validating dates. The date format I am utilizing is dd-MMM-yyyy. This control consists of two textboxes, each accompanied by a calendar extender (an AJAX control), and I have also applied a ...