Trigger a JavaScript function from ASP.NET code-behind

Here is a JavaScript function I've created:

 function returnToParent() {            
        var oArg = new Object();
        var oWnd = GetRadWindow();
        oArg.ReturnValue = "Submit";
        oWnd.close(oArg);
    }

This is how I call the function on the client side:

 <button title="Submit" runat="server" id="close" onclick="returnToParent(); return false;">
                    OK</button>

I'm trying to trigger this function on a server-side button click. To do so, I added a new button:

 <asp:Button runat="server" ID="rtxtSubmitChange" OnClick="rtxtSubmitChange_Click"  Text="Submit" />

And in the Button Click Event:

protected void rtxtSubmitChange_Click(object sender, EventArgs e)
    {
        Page.ClientScript.RegisterStartupScript(GetType(),
"MyKey",
"returnToParent();",
false);
    }

However, it seems that my code isn't working as expected. What could be wrong?

Answer №1

Give it a shot:

ScriptManager.RegisterStartupScript(this, this.GetType(), this.ClientID, "returnToParent()", true);

OR

ScriptManager.RegisterStartupScript(Page, Page.GetType(), this.ClientID, "returnToParent()", true);

For further information check out :ScriptManager.RegisterStartupScript Method

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

React slick does not display arrows when there are 4 or more photos

I am facing an issue where the next and previous arrows are not appearing when I have 4 or more photos on react-slick. However, they show up fine when there are 3 or fewer photos. You can view my code at this link: https://codesandbox.io/s/wyyrl6zz3l ...

Utilize MaterialUI Grid to define custom styles for the ::after pseudo-element

I came across a helpful article on Stack Overflow about Flex-box and how to align the last row to the grid. I'm interested in implementing it in my project: .grid::after { content: ""; flex: auto; } However, I'm not sure how to inc ...

Ways to retrieve information from a specific key

I'm currently facing a challenge accessing specific data objects that are referenced by keys. In this particular scenario, the "applicant" data is nested within an Event object. My goal is to extract this data and create a new object from it. While I ...

Preventing form submission with JavaScript by implementing multiple validation checks

Preventing a form from submitting when validation returns false is possible. Here's an example: <form name="registration" action="registration.php" onsubmit="return validate()"> <!-- some inputs like: --> <input type="text" id="us ...

Refresh Form Following Submission

When using a react form that triggers a graphql mutation upon button click, the text entered in the form fields remains even after the mutation has been executed. This necessitates manual deletion of text for subsequent mutations to be run. Is there a way ...

What could be causing this issue with my Mongoose.js program when it freezes during a 'nested' save operation?

[edit]: I made a revision to the previous question, providing a very precise reproducible example. This is the program I've created. I have developed two Schemas named ASchema and BSchema with collections A and B respectively. Then, I generated ...

Is it possible to continuously divide or multiply numbers by 2 without encountering any rounding errors when working with floating point numbers?

binary can only represent those numbers as a finite fraction where the denominator is a power of 2 Are calculations done in binary/floating point format still accurate, even after multiple additions or multiplications by 2 without any rounding errors? co ...

JavaScript is abstaining from generating a div element

I've been struggling for the last couple of hours to create a special div element with specific properties, but no matter what I try, it just won't work. Can someone please point out where I'm going wrong? function generateRoundDiv() { var ...

Service Worker unable to register due to an unsupported MIME type ('text/html') declared

Working on a project using create-react-app along with an express server. The pre-configured ServiceWorker in create-react-app is set up to cache local assets (https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README ...

What is the best way to place an <a href> tag within an ASP.NET table in the code-behind file?

Possible Duplicate: How can I generate new Hyperlinks dynamically in ASP.NET? I am dynamically inserting tables in my code and I need to do this through coding in my code behind file. Below is the code snippet I am working with: <table> < ...

The link does not respond to the first click

I'm having an issue with the search feature on my website. The page includes an auto-focused text input element. As the user types, an ajax request is made and JQuery fills a div with search results. Each result is represented by an <li> elemen ...

Using Angular JS to filter ng-repeat with a combination of a field and a dropdown

There seems to be a lot of conflicting information online regarding this issue, but I am in search of a concise solution. My dataset consists of a list of countries around the world, including their name, ISO alpha code, region, and more. To display this ...

What steps are necessary to add a Contact Us form to my HTML website?

Currently, I am searching for a way to add a "Contact Us" section to my website that is completely HTML-based. I believe the best approach would involve using a PHP script to handle sending emails from a form on the Contact Us page, but I am not familiar ...

What is the best way to convert an HTML table into an array of objects?

In my Angular Protractor end-to-end (e2e) tests, I need to perform assertions on an HTML fragment similar to the following: <table> <thead> <tr> <th>Name</th> <th>Age</th> ...

Visual Studio is mistakenly flagging my perfectly accurate SQL query as incorrect

I can't seem to figure out this one problem that's been bothering me. What could be wrong with the following code snippet? string id = Request["ids"]; SqlConnection con = new SqlConnection(helper.conn); SqlCommand com1 = ...

New and one-of-a-kind C# 90-ball Bingo cards

I am developing a bingo card generation system that includes 6 tables. Each table contains 3 rows and 9 columns, with 5 numbers and 4 empty spots in each row. The columns are divided as follows: Column 1: 1-9, Column 2: 10-19, Column 3: 20-29, Column 4: 3 ...

What is the best way to remove a nested JSON key in a dynamic manner

Here is a sample json for reference: { "search": { "facets": { "author": [ ], "language": [ { "value": "nep", "count": 3 }, { "value": "urd", "count": 1 } ], "source": [ { "value": "West Bengal ...

the location of the obj and mtil files

I am looking to showcase a high-quality 3D model on my website, but I'm facing an issue with locating the mtl and obj files. Currently, I am developing a program using Visual Studio for web development and I want this 3D model to be integrated into th ...

Ways to display an SVG spinner prior to a substantial UI refresh

I am currently facing an issue with updating 10 apexcharts bar charts simultaneously in a Vue app. When this process occurs, it takes approximately one second to load completely, and during that time, I would like to display an svg spinner. However, the co ...

The challenge with using Telerik Rad Textboxes in conjunction with JavaScript

I am facing an issue where the server data is not displayed in a Rad Textbox until I click on it using JavaScript. The data is being populated correctly inside the textbox, but it remains invisible until clicked. function fillTextBox(name, sku, plu, nam ...