I am looking to run a Java script code on a .cs page

I am currently working on a change password popup window. My goal is to send the user's username and newly changed password to the parent window once it has been successfully updated in the popup. I would also like the popup to automatically close after a few seconds. However, I am encountering an issue where I am unable to call the JavaScript function from the .cs file. Below is the code snippet I have tried so far. Can anyone provide guidance on how to solve this problem?

string script = "<script>" + "return updateParent();";
         if (!ClientScript.IsStartupScriptRegistered("someKey"))
         {
             ClientScript.RegisterStartupScript(this.GetType(), "someKey", script);
         }   

<script type="text/javascript">
       function updateParent() {
           opener.document.form1.getElementById(Username).value = document.form1.getElementById(Username).value;
           opener.document.form1.getElementById(pswrd).value = document.form1.getElementById(new_paswrd).value;
           self.close();
           return false;
       }
</script>

Answer №1

Modify the following:

var script = "<script>" + "return updateParent();";

to:

var script = "<script>" + "return updateParent();" + "</script>";

Happy coding!

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

JavaScript/TypeScript Asynchronous Filtering on AsyncIterable<T>

I am currently working with an AsyncIterable variable and I am trying to apply a filter on it. Take a look at the example below (pseudo code) - class SomeClass { private SOME_CONST= "ABCDE"; private async someFunction(): Promise<strin ...

What are effective solutions to reduce the increasing Next.js bundle size caused by dynamic component lookup?

tldr: For more information, please visit the repository. The common.js file includes all dependencies, even though only one is used on the current page. http://localhost:3000/components/ComponentOne http://localhost:3000/components/ComponentTwo Live dem ...

Experiencing a problem during the installation of npm express for testing purposes

Having trouble installing supertest as I keep receiving errors in the terminal. When I run 'supertest -v', it says command not found. Even after installing, I encounter the following error. Any suggestions would be greatly appreciated. I attempte ...

Stop user from navigating to specific route using React-router

I am currently utilizing react-router with history useQueries(createHashHistory)(), and I have a requirement to restrict navigation to certain routes based on the route's configuration. The route configuration looks like this: <Route path="/" name ...

Erase the Japanese content from the input

Having trouble removing Japanese characters from a text input box using jQuery. Here is the code I am trying: $('#email').keyup(function () { this.value = $(this).val().replace(/[^a-zA-Z0-9!.@#$%^&*()_-]/g,''); }); // try &l ...

Tips for efficiently loading large amounts of HTML data using jQuery AJAX as needed

Recently, I completed the development of our company's website where each product detail is displayed in one record on an ASPX page. Sometimes, the HTML data is extensive, requiring users to scroll multiple times to read the content in its entirety. I ...

Passing information from Silverlight to an aspx webpage

Is there a way to send data from my Silverlight application to an aspx page without passing parameters in the URL? I believe using a POST method would be the most appropriate solution, but I am unsure of how to implement it. Can anyone provide guidance o ...

The client side script "/socket.io/socket.io.js" was not located, therefore the Express-generator project was used instead

I have been working on integrating the "chat-example" from Socket.IO's official website into an Express-generator generated project while keeping the structure of the project intact. I have made minimal changes to the code to fit it into the existing ...

Generate menu options in real-time

I have developed a React single page application using the NASA Picture of the Day API. I am looking to incorporate a drawer feature that displays a history of previously shown images, but only showing their dates. However, I am unsure of how to dynamical ...

Implementing a feature to dynamically add multiple markers on Google Maps

Currently, I am utilizing the .text() method to extract latng from the html. <div class="latlng"> -33.91722, 151.23064</div> <div class="latlng"> -32.81620, 151.11313</div> As a result, I am using $(latlng).text() to retrieve the ...

Is there a way to group together select values in a dropdown menu under a shared category?

If I have a dropdown menu that looks like for example: <select> <option value="1">1</option> <option value="3">3</option> <option value="2">2</option> <option value="4">4</option> </select&g ...

Replacing an array element in React.js

Here is a React.js code snippet where I am trying to utilize an array called distances from the file Constants.js in my Main.js file. Specifically, I want to replace the APT column in the sampleData with a suitable value from the array distances extracted ...

The art of overriding React class methods

I am attempting to implement a class composition in react: class Entity { constructor(props) { super(props); } renderPartial() { return (<div>Entity</div>) } render() { return (<div>header {this.renderPartial()}< ...

Refresh KendoUI Grid data with latest additions

I currently possess: $.post('buying-grid/split/' + config.route.params.id, item).success(function(data){ var ds = new kendo.data.DataSource(); ds.data(data) $('#buyingGrid').data('ke ...

What is the best way to turn off the legends in chart.js?

I'm having trouble customizing a chart using chart.js because I can't seem to disable the legends within the canvas element. However, I still want to style the legends elsewhere on the page using generateLegend(). Can anyone provide assistance wi ...

Update the state both before and after executing the API call

I'm facing an issue with the setState function where it seems to be getting called again before completing the previous batch of state updates. My data object has the following structure: [{ id: 0, loading: false }] On my webpage, I have toggle butt ...

Embed the Script Manager within the master page

Should the script manager be placed in the master page? ...

Styling an active link in Next.js using Styled Components

Looking for a way to customize the active link style using styled components. I have a navigation bar where the currently active link should have a specific style applied. Any suggestions are appreciated! import React from 'react' import Link f ...

Angular utilizing external parameter for Ajax requests

As a newcomer to Angular, I am eager to upgrade some old jQuery code with AngularJS. The task at hand is to extract a string from a span element, split it into two separate strings, and then use these as parameters in a GET request. I am dedicated to lea ...

Difficulty with rendering a React component in a basic demonstration

I'm trying to display "Hi", but even though I'm not getting any errors, nothing is showing up on the screen. Can anyone assist with this issue? <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/15. ...