ShowModalDialog of javascript is not closing from ASP Code behind and opens a new pop up of same page

Introduction: What is and why to use SHowModalDialog : 

In Many application, many of popups are implemented using window.showmodaldialog which restricts user to finish work on popup before changing focus to any other part of application.  For exaple just try to shut down your Smartphone and you will be prompt with a message that will force you to confirm your decision which probably uses ModalPopUp. It freezes everything in backgrund and without getting any input from your side it doesn't allow you to change something in background

Issue :

Generally an issue comes that while using ShowModalDialog of javascript doesn't closes from ASP Code behind and opens a new pop up of same page. To solve this issue just add <base target="_self"/> in <head> tag. Below I have shown an example how to use a ShowModalDialog and close it.

<head runat="server">
<base target="_self" />

protected void ButtonClose_Click(object sender, EventArgs e)
Response.Write("<script language='javascript'> { self.close() }</script>");


Popular posts from this blog

Search data in Gridview on Textbox Key press event using JQuery in Asp.Net- C#

StateCode and StatusCode Values for mostly used entities in Microsoft Dynamics CRM 2013

Dumps for Microsoft Dynamics CRM MB2-703 Practice Exam Questions Free

How to import CSV files into DataTable in C#

How to show enlarge image when mouse hover on image or link in Asp.Net(c#) using JavaScript

go to top image