Execute code after window is closed

While working on a project in asp.net (vb), I encountered an issue where the value of a textbox is being set before the user closes the window. Is there a way to prevent this from happening?

 Sub btnSelectDate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSelectDate.Click

    Dim Window As String
    Window = " window.open('About.aspx', 'MsgWindow', 'width=500, height=500'); "

    ClientScript.RegisterClientScriptBlock(Me.GetType, "date", Window, True)

    textboxvalue.Text = "hello"

    Page_Load()

End Sub

Answer №1

If you need to update the text of a textbox after closing a popup window, you can achieve this in client-side code by following these steps:

    Dim jsCode As String
    jsCode = "var wnd = window.open('About.aspx', 'MsgWindow', 'width=500, height=500'); wnd.onbeforeunload = function() { document.getElementById('textboxvalue').value = 'Hello'; };"
    ClientScript.RegisterClientScriptBlock(Me.GetType, "date", jsCode, True)

In this scenario, ensure that the ID referenced as textboxvalue matches the actual ID of the TextBox element in the HTML markup.

UPDATE - Implementing button click processing in client-side code:

<asp:Button ID="btnSelectDate" runat="server" OnClientClick="ProcessSelectDate(); return false;" />

<script>
    function ProcessSelectDate()
    {
        var wnd = window.open('About.aspx', 'MsgWindow', 'width=500, height=500');
        wnd.onbeforeunload = function () { document.getElementById('textboxvalue').value = 'Hello'; var form = document.forms['form1']; form.submit(); };
    }
</script>

It is important to note that in the provided script, form1 represents the specific ID assigned to the form on the page.

Answer №2

Give this a shot:

1- Insert the following code into the script file that closes the window

window.opener.location.href = "YourPage?FromPopup=1"

2- Check from the Parent window

Request.QueryString["FromPopup"]

Feel free to add your own code here

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

Vue: Choosing an option during the execution of setInterval

I'm facing an issue where I can't select an option while a setInterval function is running on the page. The main problem is that an option cannot be selected at the same time as the setInterval timer fires. let updateDelay = 100; var vueObj = ...

"Although disabled, input elements can still be focused on in Firefox browser

Illustrative example let userInput = document.createElement("input"); userInput.id = "user-input"; userInput.type = "number"; userInput.className = "user-number-input"; userInput.disabled = true; document.body.appendChild(userInput); .number-inp ...

What is the best way to create an image carousel that continuously loops instead of resetting?

Currently tackling an issue with my image carousel project. The automatic function of the slider is not functioning as desired. Instead of looping back to the first image when it reaches the last one, it moves all the way back to the beginning, displaying ...

A user code came across a System.Web.HttpException which had not been handled. The message indicated, "There is a field or property with the

Encountering an issue with my ASP.NET/C#/SQL project while running it on an XP box. The exception I receive is as follows: System.Web.HttpException was unhandled by user code Message="A field or property with the name 'DisplaySchemaTables()' was ...

The hidden absolute positioned div disappears once the sticky navbar becomes fixed on the page

Whenever my navbar reaches the top of the screen, the links in the dropdown menu disappear. I followed tutorials and examples from w3schools to build my webpage. Specifically: howto: js_navbar_sticky howto: css_dropdown_navbar This code snippet exempli ...

Unresponsive JavaScript on specific element IDs

I'm experimenting with making three lines perform different animations: line 1 rotating 45deg and translating, line 2 becoming opaque, and line 3 rotating -45deg and translating. Check out my JS Fiddle here <a href="#"><div id="menu" onclic ...

Experiencing issues with creating HTML using JavaScript?

I'm a JavaScript novice and struggling to figure out what's wrong with my code. Here is the snippet: var postCount = 0; function generatePost(title, time, text) { var div = document.createElement("div"); div.className = "content"; d ...

Enhance Three.js 3D model visuals with textured surfaces using Fabric.js canvas as a dynamic texture

Exploring the world of Three.js for the first time, I am embarking on a project that involves leveraging a pre-existing 3D model and altering one of its materials to utilize a Fabric.js canvas as its texture. However, I've hit a roadblock where the te ...

In the process of making a request with axios in an express server

Struggling with a simple call to an API using Axios with Express, and I can't figure out why it's always pending in the browser. Here is my route: var express = require("express"); var router = express.Router(); const controller = require("../. ...

Try refreshing the webpage if the AJAX Update Panel experiences an issue

Currently, my website displays the status of multiple servers and provides information about user numbers in various systems. I have set up an AJAX UpdatePanel with an asp:Timer control to automatically refresh the data. Although this setup works smoothly ...

Organizing code for various controls within a Windows form (VB.NET) by creating distinct classes and storing them in separate files

I am working on a Windows Form application that includes various buttons, textboxes, and Tab controls. Currently, the source code is automatically generated within the Form class in a single file whenever I double-click on a button, tab, or textbox. Is t ...

Transforming the NavBar in React: A guide to dynamically updating values

I am facing an issue with my NavBar that changes based on certain events. The current setup works fine, but I don't want to render it in every class that loads a new page. Initially, I had the NavBar rendering inside App.js so it could appear on all p ...

Issue with button style in dropdown menu in Twitter Bootstrap

<nav class="nav-collapse user"> <div class="user-info pull-right"> <img src="http://placekitten.com/35/35" alt="User avatar"> <div class="btn-group"> ...

Having trouble transferring form data from a React.js form to a Flask API, as it is not permitting submission to MongoDB

I am currently working on a project to create a user form using react.js, python (Flask), and mongodb. Unfortunately, I am facing an issue where none of the input data is being sent to the Flask backend. Does anyone know how I can troubleshoot this problem ...

Avoiding page refresh while utilizing the ng5-slider component in Angular

I am currently working with an ng5-slider that has a customizable range from 0 to 1000. However, I have encountered an issue when adjusting the slider at the bottom of the page - it refreshes and automatically takes me back to the top of the page. I would ...

Vue.js computed property experiencing a minor setback

I'm currently working on developing a test-taking system using Vue and Laravel. When a user inputs the test code and email address, they are directed to the test page. To display all the test questions based on the entered code, I implemented a naviga ...

What is the best way to incorporate server-side rendered content from a CMS to hydrate Vue.js?

Consider this scenario: content is managed through a traditional CMS such as Joomla or Drupal content is provided by the CMS as fully rendered HTML and CSS In the Frontend React.js should be utilized for all UI interactions. Despite going over most of R ...

Unable to retrieve information from the json-server

For my current project in Backbone.js, I'm utilizing the json-server package to populate it with data. I've created a db.json file containing the data and executed the command json-server --watch db.json. The server started successfully and is ru ...

Filtering an array of <input> values in JavaScript based on the number of characters they contain

Can someone help me figure out why this JavaScript code isn't working as expected? The intention is to grab the input value from a text box (a string of words separated by spaces), convert it into an array, and then remove any words that are less than ...

A pair of buttons each displaying a unique div block

I am facing an issue with my jQuery script. I want to be able to click on one of the previewed text associated with a button and then have the other one close automatically. The desired effect is for the text to slide down using slideDown() and disappear ...