472,141 Members | 1,171 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,141 software developers and data experts.

Modal Window Posting Back to Itself

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
0 1740

Post your reply

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

Similar topics

2 posts views Thread by martin de vroom | last post: by
1 post views Thread by amith | last post: by
2 posts views Thread by John | last post: by
3 posts views Thread by Earl Teigrob | last post: by
10 posts views Thread by Guadala Harry | last post: by
2 posts views Thread by Mike | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.