Postback on Parent form from child form javascript

shawndewet

New member
Joined
Jun 4, 2004
Messages
1
Programming Experience
3-5
I have 2 different .aspx files that require the input of a stock code. The stock code field on each form is defined as follows:-
<INPUT id="txtStockCode" type="text" maxLength="30" name="txtStockCode" runat="server">

Next to the field on each form I have a clickable image defined as follows:-
<IMG id="imgLookupStockItem" onclick="window.open('../frmLookup.aspx?Object=StockCodes')" src="../images/binoc.ico" name="LookupStockItem">

So when the user clicks on the binoculars image from either form, a new window is opened and the user is presented with a list of stock codes in a table built up with a stylesheet. The user makes his/her selection by clicking on the relevant stockcode, which is defined in the stylesheet as follows:-
<xsl:template match="StockCode">
<td><a href="#" onclick="doOK(this.innerText)">
<xsl:value-of />
</a>
</td>
</xsl:template>

As you can see this creates clickable text that calls a function called doOK, passing to the function the value of the stockcode selected. This function is defined in the CSS as follows:-
...
</HEAD>
<SCRIPT LANGUAGE="javascript">
<![CDATA[
function doOK(fieldX) {
var item = window.opener.document.getElementById("txtStockCode");
item.value = fieldX;
item.focus();
window.opener.__doPostBack("txtStockCode","");
window.close();
}
]]>
</SCRIPT>
<BODY>
...


On each parent form I have the following event handler defined:-
Private Sub txtStockCode_ServerChange(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtStockCode.ServerChange

The idea of all this is to populate the parent form's txtStockCode control with the selected stockcode, and then do a postback on the parent form, thereby raising and executing the above event handler. Finally the child form is to be closed. The scary thing, and what this post is all about, is that on one of the parent forms this works PERFECTLY! The postback happens, the event is serverchange event is fired and handled, and the child form is closed. But on the other parent form this does NOT work.

What happens is that the parent form's txtStockCode control gets the value of the selected stockcode, and the parent form gets the focus, but the child form remains open behind the parent form, with "Error on page" in its statusbar.

Could anybody please explain to me why this is? Let me know what other information you may need in order to answer this and I will gladly provide it. This is really freaking me out.

Thanks a mil'
 
Top Bottom