By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,650 Members | 1,778 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,650 IT Pros & Developers. It's quick & easy.

Modal Window Posting Back to Itself

P: 1
I've seen many posts discussing the options we have when using modal windows within a web based application. Often times it seems the greatest hurdle is simply getting the modal window to post back to itself. It appears that most of these threads where this was discussed have been archived, so I'm bringing this topic up again to offer a couple suggestions on this topic.

I noticed that most people use the concept of posting to an iFrame. I used to do this with some degree of success, but you wind up with a bunch of extra pages in your app - 1 to be the modal window with just an iFrame on it and the other page to be the form post target which handles data changes, etc.

My suggestion would be to create a script that runs each time the page is opened as a modal window which would assign a name to itself (the current window).
Expand|Select|Wrap|Line Numbers
  1. ...
  2. </head>
  3. <body>
  4.  
  5. <script language=javascript type="text/javascript">
  6.     window.name = "MyModalPopup";
  7. </script>
  8.     <form ...
Then within the form declaration, you can specify the named window to submit to:

Expand|Select|Wrap|Line Numbers
  1. ...
  2. <form id="form1" runat="server"  target="MyModalPopup">
  3. ...
It is the most elegant solution I have found so far. Also, most modal popups have some sort of Save/Cancel buttons on them. I have had great success by using the following code to get these to work. My example shows it in the ASP.NET context, but it can easily adapt to classic asp without the server roundtrip.

Handle the Cancel routine:

Expand|Select|Wrap|Line Numbers
  1. Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCancel.Click
  2.         Response.Write("<SCRIPT language=javascript>window.close();</SCRIPT>")
  3.     End Sub
  4.  
Handle the Save routine:

Expand|Select|Wrap|Line Numbers
  1. Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
  2.         'example call to a function returning boolean value
  3.         If UpdateDB() Then
  4.             'this is line below is optional depending on if you want to close
  5.             'the window automatically or not.
  6.             Response.Write("<SCRIPT language=javascript>window.close();</SCRIPT>")
  7.         Else
  8.             'write some sort of error message or js alert to the page notifying 
  9.             'the user of the updatedb error
  10.         End If
  11.  
  12.     End Sub
  13.  
I've always gotten great ideas from anonymously browsing this forum...I hope this contribution can help someone out there!
Feb 21 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.