Tuesday, October 23, 2007

Post data to popup window

This is one of the most common requirements we deal with... how to post base page data to a popup window? There are many ways we do this like,
  • passing data by query string
  • passing data using session
  • passing data using javascript
The first 2 methods are obvious and simple. So is the third option. Let's look at how we can go about doing it. The idea is simple: get the handle of the popup window and set values of controls. Simple javascipt that does this would look like:
<script language="javascript">
function pops(pageName,windowName)

{
var popWin = null;
var windowstring;
popWin = window.open(pageName, windowName, windowstring);
popWin.focus();
popWin.document.getElementById('txtField1').value = 'My Test Value';
}
<script>

You get the idea...
Love coding!