Popup window writeback problem

M

maxrawson

Greetings all:

I have an asp.net application that is coded mainly in vb.net. I have
successfully cut and pasted some javascript into my application that
mimicks the datetime picker control in vb. I wanted to try to use that
same code for another popup style window that displays a list of
airport codes in a datagrid. The desired results would be that when an
airport code (the datagrid's key field) is clicked the value would
write back to the parent page's textbox.

So far I have been able to get the popup window to display but when I
click on an airport code in the datagrid the window does not close nor
does the value write back to the parent page control.

Parent page HTML that opens the popup:

<TD>
<SPAN id="aircode1">
<A style="FONT-SIZE: xx-small"
href="Javascript:AirCode_window=window.open('/AdvTravel/AirCode.aspx?formname=document.AdminBookingTDetails.txtTDDptFrom','AirCode_window',
'width=400');AirCode_window.focus()">Airport Code</A>
</SPAN>
</TD>
<TD>
<asp:TextBox id="txtTDDptFrom" runat="server"></asp:TextBox>
</TD>

Popup window HTML that displays the airport codes and is supposed to
writeback the code:

<HTML>
<HEAD>
<title>US Airport Codes</title>
<script runat="server">
Private Sub dgdAirCodes_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
dgdAirCodes.ItemCommand
Dim strjscript As String = "<script language=""javascript"">"
strjscript = strjscript & "window.opener." &
HttpContext.Current.Request.QueryString("formname") & ".value = '" &
Server.UrlEncode(dgdAirCodes.DataKeys(e.Item.ItemIndex).ToString) &
"';window.close();"
strjscript = strjscript & "</script" & ">" 'Don't Ask, Tool Bug
Literal2.Text = strjscript
End Sub
</script>
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form id="AirCode" method="post" runat="server">
<TABLE width="400">
<tr>
<td><asp:dropdownlist id="ddlState" runat="server" Width="136px"
AutoPostBack="True"></asp:dropdownlist><asp:textbox id="Literal2"
runat="server"></asp:textbox></td>
</tr>
<tr>
<td>
<asp:datagrid id="dgdAirCodes" runat="server" PageSize="50"
Font-Size="XX-Small" GridLines="Vertical" CellPadding="3"
BackColor="White" BorderWidth="1px" BorderStyle="None"
BorderColor="#999999" AutoGenerateColumns="False" AllowSorting="True"
OnItemCommand="dgdAirCodes_ItemCommand">
<FooterStyle ForeColor="Black"
BackColor="#CCCCCC"></FooterStyle>
<SelectedItemStyle Font-Bold="True" ForeColor="White"
BackColor="#008A8C"></SelectedItemStyle>
<AlternatingItemStyle
BackColor="Gainsboro"></AlternatingItemStyle>
<ItemStyle ForeColor="Black"
BackColor="#EEEEEE"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#000084"></HeaderStyle>
<Columns>
<asp:ButtonColumn Text="Code" DataTextField="Code"
SortExpression="Code" HeaderText="Airport Code">
<HeaderStyle HorizontalAlign="Center" Width="30px"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:ButtonColumn>

*****Unnecessary datagrid details removed********

<HeaderStyle Width="150px"></HeaderStyle>
</asp:BoundColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="Black"
Position="TopAndBottom" BackColor="#999999"
Mode="NumericPages"></PagerStyle>
</asp:datagrid></td>
</tr>
</TABLE>
</form>
</body>
</HTML>
 
R

Randy Webb

Greetings all:

I have an asp.net application that is coded mainly in vb.net. I have
successfully cut and pasted some javascript into my application that
mimicks the datetime picker control in vb. I wanted to try to use that
same code for another popup style window that displays a list of
airport codes in a datagrid. The desired results would be that when an
airport code (the datagrid's key field) is clicked the value would
write back to the parent page's textbox.

So far I have been able to get the popup window to display but when I
click on an airport code in the datagrid the window does not close nor
does the value write back to the parent page control.

Parent page HTML that opens the popup:

<TD>
<SPAN id="aircode1">
<A style="FONT-SIZE: xx-small"
href="Javascript:AirCode_window=window.open('/AdvTravel/AirCode.aspx?formname=document.AdminBookingTDetails.txtTDDptFrom','AirCode_window',
'width=400');AirCode_window.focus()">Airport Code</A>
</SPAN>
</TD>
<TD>
<asp:TextBox id="txtTDDptFrom" runat="server"></asp:TextBox>

Instead of posting your ASP code, post the code that the browser gets.
Then its a simple matter of copy/pasting to test it.
 
R

RobG

Greetings all:

I have an asp.net application that is coded mainly in vb.net. I have
successfully cut and pasted some javascript into my application that
mimicks the datetime picker control in vb. I wanted to try to use that
same code for another popup style window that displays a list of
airport codes in a datagrid. The desired results would be that when an
airport code (the datagrid's key field) is clicked the value would
write back to the parent page's textbox.

So far I have been able to get the popup window to display but when I
click on an airport code in the datagrid the window does not close nor
does the value write back to the parent page control.

Here is a trivial example:

****************
Parent window
****************

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Window returns values</title>
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1">
<script type="text/javascript">
// tgtElement: element to update (is also caller here)
// winSource : the URL of the resource to load
// theWindow : window object reference
var theWindow;
function openWindow(tgt,winSource) {
theWindow = window.open(winSource,'',
'top=300,left=700,width=300,height=100');

// create a reference to the element to update in the
// popup window
theWindow.tgtElement = tgt;
}
</script>
</head>
<body onload="this.window.name = 'robWin';">
<form name="winOpener">
<input type="text" name="dataField" onclick="
openWindow(this,'dataWindow.html');
">
<input type="reset" value="reset" onfocus="blur();">
</form>
</body>
</html>



****************
Popup window (dataWindow.html)
****************

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Data window</title>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
</head>
<body>
<form action="">
<select name="data">
<option value="option01" selected>Option 01</option>
<option value="option02">Option 02</option>
<option value="option03">Option 03</option>
</select>
<input type="button" value="Accept selected value" onclick="
tgtElement.value =
this.form.data[this.form.data.selectedIndex].value;
window.close();
">
</form>
</body>
</html>


The only caveat is that opening a window this way in Firefox
creates an error:

Error: [Exception... "'Permission denied to get property
XULElement.selectedIndex' when calling method: ...

But the script runs OK. I can't find out how to prevent the
error. IE seems quite happy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top