父页面放一个图形按钮和一个TEXTBOX,代码如下:
<asp:TextBox ID="sku_id" runat="server" AutoPostBack="True" onclick="receipt_search_sku_Click" CausesValidation="True"></asp:TextBox>
<asp:ImageButton ID="receipt_search_sku"
OnClientClick="popUp(‘receipt_select_sku.aspx‘)"
runat="server" top="0"
ImageUrl="~/img/search.png" onclick="receipt_search_sku_Click" />
<script type="text/javascript">
function popUp(url) {
height = 500;
width = 700;
var paramsChrome = ‘height=‘ + height + ‘, width=‘ + width + ‘, top=‘ + (((window.screen.height - height) / 2) - 50) +
‘,left=‘ + ((window.screen.width - width) / 2) + ‘,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no‘;
objSubWin = window.open(url, "Popup", paramsChrome);
objSubWin.focus();
}
function SetValue(val) {
var amount = document.getElementById(‘<% = sku_id.ClientID %>‘);
amount.value = val;
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
子页面,放一个gridview读取数据库的内容,当鼠标点击时,返回gridview的元素,同时关闭子页面;
父页面同时接收子页面的返回值;
子页面表头放一个函数:
<script type="text/javascript" >
function cc(infor_id) //参数分别为id,name和password
{
if (window.opener != null && !window.opener.closed) {
window.opener.document.getElementById("sku_id").value = infor_id;
window.close();
}
}
</script>
后台代码,用GRIDVIEW的鼠标点击事件,去触发该函数
protected void GridView_sku_select_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//string w = e.Row.Cells[0].ClientID;
e.Row.Attributes.Add("onclick", "cc(‘" + e.Row.Cells[0].Text + "‘)");
}
}