Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
i m opening an Webpage(Clock.aspx) from window.showModalDialog of javascript.In the Clock.aspx i have a button and i want that when the user click on that button the Clock.aspx page will be closed. I dont want to use onClientClick() method of javascript as some server side database insertion is going on and after the insertion i want to close this page.

The Code behind of the button is as follows:-

C#
protected void btnStop_Click(object sender, EventArgs e)
    {
        _nonProduction = new NonProduction();
        if (Session["LastNonProdTimeID"] == null)
        {
        }
        else
        {
            int NonProdTimeEntryID = Convert.ToInt32(Session["LastNonProdTimeID"]);
            //Updating the TimeSpent
            isTimeSpentUpdated = _nonProduction.UpdateTimeSpentInDB(NonProdTimeEntryID);
            if (isTimeSpentUpdated == true)
            {

                string timespent = Convert.ToString(_nonProduction.GetTimeSpent(NonProdTimeEntryID));
                string msg = "Total time consumed  in " +HiddenTaskname.Value.ToString()+": " + timespent.ToString() + " Minutes";
                ClientScript.RegisterStartupScript(typeof(Page), "closePage", "<script type='text/JavaScript'>window.close();</script>");

                //ShowPopUpMsg(msg);
            }
            
        }



    }


Here when i m clicking on the Button one more (Clock.aspx)pop up is appearing and window is not closing. Please help me that how i close the ShowModalDialog from server side code. Thanks in Advance.
Posted
Updated 10-Jul-12 19:13pm
v3

I had added <base target="_self">to the head section of the clock.aspx page and then it works fine for me.
 
Share this answer
 
your code seems to be okay.

try

XML
Response.Write("<script>window.close();</" + "script>");
Response.End();


If you are using Scriptmanager in your page then use

ScriptManager.RegisterStartupScript(Page, Page.GetType, "closePage", "<script type='text/JavaScript'>window.close();</script>", true);
 
Share this answer
 
Comments
Dharmenrda Kumar Singh 11-Jul-12 1:03am    
Implemented the code as per you but still getting the same problem, when i m clicking on the button it is opening a new pop up of clock.aspx page but the window is not closing.I had also changed the function like your code and then call in my code but once i m clicking a new pop up of Clock.aspx is coming but now closing the webpage.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900