locked
close aspx page after executing code behind RRS feed

  • Question

  • User136609187 posted

    I am working in vs 2008, C#.

    Load event in my aspx page is having a set of database operations .So after completing those operations i want to close the aspx page.

    for that i am calling 

    window.close() methond onload event of the body. Its closing the aspx page but it is showing the confirmation message before closing the page.

    I dont want to show that message box.

    How can i claose an aspx page without showing any message?.

    Pls help me

    Thanks

    Chit

    Wednesday, September 22, 2010 8:14 AM

Answers

  • User-276842610 posted

    hi Chit,

    try this, it will not show confirmation message

    Response.Write("<script language=javascript>this.window.opener = null;window.open('','_self'); window.close();   </script>");

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 23, 2010 11:07 PM

All replies

  • User-1360095595 posted

    Try using: "window.open('','_self',''); window.close();"

    Assuming I understood what you mean by "I dont want to show that message box."

    Wednesday, September 22, 2010 8:26 AM
  • User-520527587 posted

    Try client side code instead of server side code. After you're done doing your C# code do this.


    string closeWindowScript = "<script language=javascript>window.top.close();</script>";
    if ((!ClientScript.IsStartupScriptRegistered("clientScript"))) {
    	ClientScript.RegisterStartupScript(Page.GetType(), "clientScript", closeWindowScript);
    }
    


    I hope that helps,

    Brendan


    Wednesday, September 22, 2010 8:28 AM
  • User136609187 posted

    Tried..but not working 

    Wednesday, September 22, 2010 8:42 AM
  • User-1614194436 posted

    take this it is working it will work only on for child window not for parent window or regular window


    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
        <script language="javascript">
        function myff()
        {
        alert("asd");
        window.open("Default4.aspx");
        window.close();
        return false;
        }
        function myff1()
        {
       
        window.close();
        return false;
        }
        </script>
        
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Button ID="Button1" runat="server" Text="Button open" OnClientClick="return myff()" onclick="Button1_Click" />
            <asp:Button ID="Button2" runat="server" Text="Button"  onclick="Button1_Click" />
        </div>
        </form>
    </body>
    </html>



    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;

    public partial class Default4 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void Button1_Click(object sender, EventArgs e)
        {

            
            Page.RegisterStartupScript("as", "<script language='javascript'>window.close();</script>");
        }
    }

    Wednesday, September 22, 2010 8:50 AM
  • User-1199946673 posted

    Its closing the aspx page but it is showing the confirmation message before closing the page.
     

    I think you mean the "The webpage you are viewing is trying to close the window" confimation message? You cannot disable this in ASP.NET, it is a setting in the client's browser....

    Wednesday, September 22, 2010 8:58 AM
  • User136609187 posted

    i want to close the page after executing all the codes in the load event without clicking any button or any other event 

    Wednesday, September 22, 2010 9:02 AM
  • User136609187 posted

    yes, the sam emessage.Is there any other way to close that aspx page after executing all the functions in the load event?

    I am opening this aspx from a vbs cript file by using windows task scheduler. 

    Wednesday, September 22, 2010 9:08 AM
  • User-1199946673 posted

    I am opening this aspx from a vbs cript file by using windows task scheduler. 
     

    So it's not supposed to be a web page? Why not do all the things you do in the page in a vbs script, or create a Console Application, instead of using a webpage....

    Wednesday, September 22, 2010 9:45 AM
  • User1949625403 posted

    hi chithra try like this definitly  it helps you in close the page in page load place this cod ein end of page laod and try it will helps you


    Response.Write("<script language=javascript>window.close();</script>");



    Wednesday, September 22, 2010 10:22 AM
  • User136609187 posted

     its a separate aspx page in my project solution. I am doing some db operations and updating db with the help of task scheduler.

    So for that i need latest csv data from my project.Thats why i am using a web page instead of console application.

    Is there any way to close the page from vb script itself?

    Wednesday, September 22, 2010 10:25 AM
  • User-1199946673 posted

     its a separate aspx page in my project solution. I am doing some db operations and updating db with the help of task scheduler.

    So for that i need latest csv data from my project.Thats why i am using a web page instead of console application.

     

    I don't hear anything why you couldn't use a seperate (Console) application to do the db operations?

    Is there any way to close the page from vb script itself?

     

    Then my question would be, where are you opening the webpage using vbs? Maybe you shoudl take a look here:

    http://www.mikesdotnetting.com/Article/129/Simple-task-Scheduling-using-Global.asax

    Wednesday, September 22, 2010 10:29 AM
  • User-276842610 posted

    hi Chit,

    try this, it will not show confirmation message

    Response.Write("<script language=javascript>this.window.opener = null;window.open('','_self'); window.close();   </script>");

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 23, 2010 11:07 PM