Steps for closing a modal popup in Asp.NET WebForms after saving data

I have implemented javascript code on my main page that triggers a popup when a link is clicked:

<script language="javascript">  

function OpenResidentialAddressWin(subscriberContactRelationGid, routeId, btn) {
    window.showModalDialog("SubscriberResidentialAddress.aspx" + BuildQueryStringValuesForSubscriber(subscriberContactRelationGid, routeId, returntxtReceiptDate().value), this, strWindowFeatures + ";scroll:no;dialogWidth:442px;dialogHeight:350px");
    location.href = location.href;
}

</script>

The above script opens the page SubscriberResidentialAddress.aspx in a modal window with various variables passed into it.

This page has sections for displaying and editing information, which are toggled based on button interactions within the window.

Currently, after saving information, the page switches to display mode. Instead, I aim to close the modal window completely and refresh the main page.

A colleague recommended using a literal control on the aspx page of the modal window and executing JavaScript post successful save. In the head section of SubscriberResidentialAddress.aspx, I added:

<asp:Literal runat="server" ID="litCloseWind"></asp:Literal>

In the code-behind, within the function triggered upon save:

  protected void btnAddSave_Click(object sender, EventArgs e)
{

////// saving-related code

 if (status.IsSuccessful)
            {
                litCloseWind.Text = "<script>this.close()</script>";
                Response.Redirect(Request.Url.AbsoluteUri, false);
            }


}

I tried the above approach, including 'litCloseWind.Text = "window.close()";', but none successfully closed the modal window after a save operation.

Is this strategy logically correct, or did I make an error somewhere? Or perhaps, was this not the best method to begin with?

Answer №1

Would you like to add a script to close the window? You can do it this way:

ClientScript.RegisterStartupScript(typeof(Page), "CLOSEWINDOW", "window.close();");

You don't have to insert any Literal Control here.

Your code will then appear as follows:

protected void btnAddSave_Click(object sender, EventArgs e)
{
    if (status.IsSuccessful)
    {
        ClientScript.RegisterStartupScript(typeof(Page), "CLOSEWINDOW", "window.close();");
    }
}

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

Using Conditions in AngularJS: Choosing Between Callbacks and Promises in a Service

I am currently faced with a specific scenario where I am uncertain whether to implement a callback or a promise. As someone who is relatively new to promises and just beginning to grasp their concept, I want to avoid falling into any potential anti pattern ...

Executing Rake tasks on the live server fails because of an issue with ExecJS

I currently have a Rails 4 application running on a RHEL 6 server. The production environment utilizes Passenger and Apache2. Recently, I've been attempting to schedule Rake tasks in the production environment using the Whenever Gem and Cron. Howev ...

Database Migrations in ASP.NET MVC 4 Production Environment

Currently developing my initial ASP.NET MVC 4 application (utilizing Entity Framework) and feeling a bit perplexed about the production database. It's interesting how the database appears to automatically generate itself (along with the correct tables ...

Defining various scopes in Angular-Rails through user-defined input

Depending on user input, I have a range of 1 to 5 lists with arrays of items in each. The lists are named list1, list2... When I declare $scope using $scope.list = [], it doesn't specify which list it is referring to. While I could statically declare ...

Should property paths be shortened by utilizing new variables for better organization?

Yesterday, someone asked me why I would introduce a variable to shorten the property path. My answer was simply that it feels easier to read. Now I am curious if there are any objective reasons to choose between the two options listed below (such as memory ...

Breaking down a string and then retrieving elements from an array

Just diving into the world of Javascript and jQuery, so I have a simple query. I've got a date that I need to break down into a string and then display it as an array. var date = "12/10/2010"; var dateArray = date.split(/); $('#printbox') ...

What is the process for deserializing nested XML data structures?

I'm a newcomer to this field, and I've been scouring for similar questions to broaden my knowledge. Currently, I am focused on maintaining XML hierarchy and creating an iterable structure. static void Main(string[] args) { Li ...

Selecting a specific element and attaching a particular class to this element, but directing it towards a different element that shares the same index in a separate node list

I am working on a project where I have two sets of identical images - one is displayed in a gallery format and the other set is hidden until its corresponding gallery image is clicked, creating a lightbox effect. For example: <ul id="gallery"> ...

Is Typescript capable of converting ES6 code to ES5 during transpilation?

Currently, I'm in the process of developing an application utilizing Angular 2 and TypeScript. My goal is to incorporate a JavaScript method, specifically 'filter' for arrays, that is compatible with IE 11+, Chrome 45+, and other similar bro ...

Implementing text truncation in JavaScript

I am seeking to transform the INPUT I have into a desired OUTPUT format. pieChart.js stackedColumnChart.js table.js and i want OUTPUT like that(wanna remove .js from ) pieChart stackedColumnChart table ...

What is the best way to include the file name and size as query parameters in Node.js?

To retrieve an image from the folder, a query needs to be passed containing the filename and dimensions like this: localhost:3000/images?filename=myImage&width=100&height=100 The initial objective is to fetch images from the designated folder, res ...

Converting dependencies during Jest test execution

Recently, I introduced tiptap-vuetify as a dependency in my Vue application, triggering the addition of 19 other modules as transitive dependencies. After integrating it, I proceeded to run my tests only to encounter the following error: Jest encountered a ...

Handling exceptions in the event that the backend URL resource cannot be accessed

I'm facing an issue with my Vue.js single file component where I am trying to catch exceptions when the URL requested by axios.post is unreachable. I have encapsulated the entire code in a try block, but for some reason, the alert in the catch block i ...

implementing automatic ajax requests when user scrolls

This is a piece of JavaScript code: $(window).scroll(function() { $.ajax({ type: "GET", url: "not_data.php", data: dataString, success: function my_func () { //show new name ...

Discovering an object that lacks a specific property using JSONPath

Here is a sample json: { "data": [ { "name": "Peter", "excluder": 1 }, { "name": "Sansa" } ] } I am looking to extract elements that do not have the ...

Modifying the color of an SVG in real-time and using it as a texture in Three.js

I have been attempting to develop a configurator using three.js, but I am currently stuck at the stage where I need to dynamically change the color of the product. My initial idea was to use an SVG as a texture, modify the fill property of the SVG, and eas ...

What is the best method to determine the currency associated with the code in dinero.js?

Is there an easy way to locate the dinero currency in the dinero.js/currencies package using its code? For example, a function called getCurrency that accepts a string as input and outputs the corresponding dinero currency. ...

vee-validate remains consistent in its language settings

Having trouble changing the error message in vee-validate, any suggestions on how to fix this? import VeeValidate from "vee-validate"; import hebrew from "vee-validate/dist/locale/he"; Vue.use(VeeValidate, { locale: "he", dictionary: { he: { me ...

What is the process for creating URL query parameters?

What is the process for generating parameters after node?_=xxxxxx? If I am using a Python script to access the URL, how can I retrieve these parameters? edit: I apologize for not providing enough information. This is my first post as a novice. I am atte ...

JavaScript Error: Unable to execute jQuery.toJSON - It is not a valid function

I stumbled upon a Tournament Bracket and I want to bring it over to our vBulletin software. Even though the script functions properly outside of vBulletin, importing it triggers an error message. function saveFn(data, userData) { var json = jQuery.toJS ...