点击子窗体给父窗体上的对象赋值
1. 父窗体:
2.子窗体(注意GridView第一列input的onclick事件,当选择checkBox时将实时给父窗体赋值)
<input id="DetailID" type="hidden" runat="server" />
<asp:TextBox ID="txtTitle" runat="server"></asp:TextBox>
<asp:DropDownList ID="ddlProgramCategory" runat="server">
<asp:ListItem Value="0">--类型--</asp:ListItem>
<asp:ListItem Value="1">台宣</asp:ListItem>
<asp:ListItem Value="2">广告</asp:ListItem>
<asp:ListItem Value="3">音乐</asp:ListItem>
</asp:DropDownList>
<input id="btnAdd" type="button" value='新建' onclick="GetAddUrl();" />
<script language="javascript">
function $(s){return document.getElementById(s);}
function isNull(_sVal){return (_sVal == "" || _sVal == null || _sVal == "undefined");}
//获取地址栏参数
function GetUrl(name)
{
var URLParams = new Array();
var aParams = window.location.search.substr(1).split('&');
for (i=0; i < aParams.length; i++)
{
var aParam = aParams[i].split('=');
URLParams[aParam[0]] = aParam[1];
}
return URLParams[name];
}
function GetAddUrl()
{
var ddlProgramCategory = $('<%=ddlProgramCategory.ClientID %>');
var TitleID = $('<%=txtTitle.ClientID %>');//获取客户端对象
var DetailID = $('<%=DetailID.ClientID %>');
var ID = GetUrl("UnitID");
var categoryID = ddlProgramCategory.options[ddlProgramCategory.selectedIndex].value;
var url="";
switch (categoryID)//根据下拉框决定链接地址
{
case "1": url = "Ad1.aspx?UnitID=" + ID; break;
case "2": url = "Ad2.aspx?UnitID=" + ID; break;
case "3": url = "MusicCategory.aspx?UnitID=" + ID; break;
}
//将需要子窗体进行填充的对象的 ClientID 传到子窗体去
url += "&DetailID=" + DetailID.id + "&TitleID=" + TitleID.id ;
if(categoryID!="0") winOpen(url);
}
//弹出打开新页面-------------------------------------------
function winOpen(url)
{
var sFeatures='height=500, width=600, top=80, left=300,toolbar=0, menubar=0, scrollbars=1, resizable=1, location=1, status=1';
url = encodeURI(url);
window.open(url,"RM_ProgramDetail",sFeatures);
}
</script>
<asp:TextBox ID="txtTitle" runat="server"></asp:TextBox>
<asp:DropDownList ID="ddlProgramCategory" runat="server">
<asp:ListItem Value="0">--类型--</asp:ListItem>
<asp:ListItem Value="1">台宣</asp:ListItem>
<asp:ListItem Value="2">广告</asp:ListItem>
<asp:ListItem Value="3">音乐</asp:ListItem>
</asp:DropDownList>
<input id="btnAdd" type="button" value='新建' onclick="GetAddUrl();" />
<script language="javascript">
function $(s){return document.getElementById(s);}
function isNull(_sVal){return (_sVal == "" || _sVal == null || _sVal == "undefined");}
//获取地址栏参数
function GetUrl(name)
{
var URLParams = new Array();
var aParams = window.location.search.substr(1).split('&');
for (i=0; i < aParams.length; i++)
{
var aParam = aParams[i].split('=');
URLParams[aParam[0]] = aParam[1];
}
return URLParams[name];
}
function GetAddUrl()
{
var ddlProgramCategory = $('<%=ddlProgramCategory.ClientID %>');
var TitleID = $('<%=txtTitle.ClientID %>');//获取客户端对象
var DetailID = $('<%=DetailID.ClientID %>');
var ID = GetUrl("UnitID");
var categoryID = ddlProgramCategory.options[ddlProgramCategory.selectedIndex].value;
var url="";
switch (categoryID)//根据下拉框决定链接地址
{
case "1": url = "Ad1.aspx?UnitID=" + ID; break;
case "2": url = "Ad2.aspx?UnitID=" + ID; break;
case "3": url = "MusicCategory.aspx?UnitID=" + ID; break;
}
//将需要子窗体进行填充的对象的 ClientID 传到子窗体去
url += "&DetailID=" + DetailID.id + "&TitleID=" + TitleID.id ;
if(categoryID!="0") winOpen(url);
}
//弹出打开新页面-------------------------------------------
function winOpen(url)
{
var sFeatures='height=500, width=600, top=80, left=300,toolbar=0, menubar=0, scrollbars=1, resizable=1, location=1, status=1';
url = encodeURI(url);
window.open(url,"RM_ProgramDetail",sFeatures);
}
</script>
2.子窗体(注意GridView第一列input的onclick事件,当选择checkBox时将实时给父窗体赋值)
<asp:GridView ID="GridView1" SkinID="gvClass2" runat="server" DataKeyNames="ID" OnRowDataBound="GridView1_RowDataBound"
AutoGenerateColumns="False" Width="100%" AllowSorting="true" OnSorting="GridView1_Sorting"
OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating" OnRowDeleting="GridView1_RowDeleting">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<input id="check" runat="server" type="checkbox" value='<%# Eval("ID") %>' title='<%# Eval("Title")%>'
class='<%# FormatTime(Eval("Length")) %>' onclick="DoClick(this);" />
</ItemTemplate>
<HeaderTemplate>
<input id="checkAll" title="全选" onclick="javascript:CheckAll(this);" runat="server"
type="checkbox" />
</HeaderTemplate>
<ItemStyle Width="5%" />
</asp:TemplateField>
</Columns>
</asp:GridView>
<script language="javascript">
function $(s){return document.getElementById(s);}
function isNull(_sVal){return (_sVal == "" || _sVal == null || _sVal == "undefined");}
//获取地址栏参数
function GetUrl(name)
{
var URLParams = new Array();
var aParams = document.location.search.substr(1).split('&');
for (i=0; i < aParams.length; i++)
{
var aParam = aParams[i].split('=');
URLParams[aParam[0]] = aParam[1];
}
//取得传过来的name参数
return URLParams[name];
}
//---------------------------------------------------------
function GetParentObj(strID)//获取父页面客户端对象
{
return window.opener.document.getElementById(strID);
}
function DoClick(obj)
{
var UnitID = GetUrl("UnitID");//获取地址栏中传来的父窗体对象的ClientID
var TitleID = GetUrl("TitleID");
var DetailID = GetUrl("DetailID");
if(!isNull(DetailID) && !isNull(TitleID))
{
var Obj_DetailID = GetParentObj(DetailID);//获取父页面客户端对象
var Obj_TitleID = GetParentObj(TitleID);
if(obj.checked)
{
Obj_TitleID.value = obj.title;//给父窗体对象赋值
Obj_DetailID.value = obj.value;
}
else
{
Obj_TitleID.value = "";
Obj_DetailID.value = "";
}
}
}
</script>
AutoGenerateColumns="False" Width="100%" AllowSorting="true" OnSorting="GridView1_Sorting"
OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating" OnRowDeleting="GridView1_RowDeleting">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<input id="check" runat="server" type="checkbox" value='<%# Eval("ID") %>' title='<%# Eval("Title")%>'
class='<%# FormatTime(Eval("Length")) %>' onclick="DoClick(this);" />
</ItemTemplate>
<HeaderTemplate>
<input id="checkAll" title="全选" onclick="javascript:CheckAll(this);" runat="server"
type="checkbox" />
</HeaderTemplate>
<ItemStyle Width="5%" />
</asp:TemplateField>
</Columns>
</asp:GridView>
<script language="javascript">
function $(s){return document.getElementById(s);}
function isNull(_sVal){return (_sVal == "" || _sVal == null || _sVal == "undefined");}
//获取地址栏参数
function GetUrl(name)
{
var URLParams = new Array();
var aParams = document.location.search.substr(1).split('&');
for (i=0; i < aParams.length; i++)
{
var aParam = aParams[i].split('=');
URLParams[aParam[0]] = aParam[1];
}
//取得传过来的name参数
return URLParams[name];
}
//---------------------------------------------------------
function GetParentObj(strID)//获取父页面客户端对象
{
return window.opener.document.getElementById(strID);
}
function DoClick(obj)
{
var UnitID = GetUrl("UnitID");//获取地址栏中传来的父窗体对象的ClientID
var TitleID = GetUrl("TitleID");
var DetailID = GetUrl("DetailID");
if(!isNull(DetailID) && !isNull(TitleID))
{
var Obj_DetailID = GetParentObj(DetailID);//获取父页面客户端对象
var Obj_TitleID = GetParentObj(TitleID);
if(obj.checked)
{
Obj_TitleID.value = obj.title;//给父窗体对象赋值
Obj_DetailID.value = obj.value;
}
else
{
Obj_TitleID.value = "";
Obj_DetailID.value = "";
}
}
}
</script>