Wednesday, December 22, 2010

Making modal dialog windows work in ASP.Net the easy way

Making modal dialog windows work in ASP.Net the easy way
Posted by raymondlewallen on December 9, 2005

Powered by WP Greet Box WordPress Plugin
This is an old solution to an old problem, but since somebody asked
me if I knew how to solve this problem, I thought I’d post the solution
here to make it easier for people to find in the future.

The problem has to do with ASP.Net and modal windows (windows opened
by parent windows using ‘window.showModalDialog()’). If you’ve ever
launched a modal window and issued a postback by clicking a button or
tried to redirect, you know that it always opens a brand new window,
and that is super annoying and unusable.

So, if you want to know how to use modal windows in Asp.Net and not
have them keep opening new windows, the solution (and I my friend will
can testify this simple solution works) does work. There are much more
elaborate solutions posted out on the internet, but trust me, its just
this easy, even though slightly inconvenient.

First, in the HEAD of EACH PAGE that will be as a modal window or called from a modal window, you have to have the following:
[code]


This name you give each page MUST be unique for each page.

Now, just set the target of the form in your page to target the name of the page the form exists on, like such:


With a completely new and blank page, the whole thing would look like this: <%@ Page Language=“VB” AutoEventWireup=“false” CodeFile=“Default.aspx.vb” Inherits=“_Default” %> Untitled Page
This entry was posted in .Net Development. Bookmark the permalink. Follow any comments here with the RSS feed for this post.


Also, adding this line in the head section will keep from spawning new windows:


<base target="_self">

[/code]

No comments:

Post a Comment