a.aspx的html:
<div><iframe src="b.aspx"></iframe></div>b.aspx的html:
<form id="form1" runat="server">
<asp:Panel ID="Panel1" runat="server" HorizontalAlign="Left"
Style="text-align:left; OVERFLOW-Y: auto;left: 0px; position: relative; top: 0px; SCROLLBAR-SHADOW-COLOR: #ecf2f9; SCROLLBAR-DARKSHADOW-COLOR: #99ccff; SCROLLBAR-FACE-COLOR: #ecf2f9; border-width:1px">
<asp:DataList ID="DLisselect" runat="server" Width="100%" OnItemDataBound="DLisselect_ItemDataBound" RepeatColumns="2" RepeatDirection="Horizontal">
<HeaderTemplate>
<table border="0" cellpadding="0" cellspacing="0" width="100%"
style="background-color:#C5D4F1;text-align:left; border:solid 1px #C5D4F1; padding:2px 2px 0px 2px; font-size:12px;">
<tr style="background-color:#f9f9f9; height:18px">
<td align="center" style="width:100px">序号</td>
<td align="left" style="width:150px">列名</td>
<td align="center">选择</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color:#ffffff;">
<td align="center" style="width:100px"><asp:Label ID="LBcolid" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"orderid") %>'></asp:Label></td>
<td align="left" style="width:150px"><%#DataBinder.Eval(Container.DataItem,"colalias") %></td>
<td align="center"><asp:CheckBox ID="CBisselect" runat="server"/></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr style="background-color:#ffffff;">
<td style="width:100px"></td>
<td style="width:150px"></td>
<td></td>
</tr>
</table>
</FooterTemplate>
</asp:DataList>
</asp:Panel>
<div style="margin-top:10px;">
<asp:Button ID="BtnSave" runat="server" Text="保存条件" OnClick="BtnSave_Click" />
</div>
</form>
b.aspx.cs的codebehind:
单击“保存条件”button执行的事件:
protected void BtnSave_Click(object sender, EventArgs e)
{
CheckBox cbselect = null;
for (int i = 0; i < this.DLisselect.Items.Count; i++)
{
cbselect = this.DLisselect.Items[i].FindControl("CBisselect") as CheckBox;
if (cbselect != null && cbselect.Checked == true)
dtColumn.Rows[i]["isselect"] = true;
else
dtColumn.Rows[i]["isselect"] = false;
}
dtColumn = XQuery.SetOrderID(dtColumn);
if ((!string.IsNullOrEmpty(Login_id)) && (!string.IsNullOrEmpty(Query_no)))
bllxq.BuildQueryPersonal(dtColumn, Login_id, Query_no);
}
问题描述:我想在是想的效果是:我想在a.aspx里面设置一个button来激发和b.aspx里面的"保存条件"button一样的效果。
1、这种效果可以实现吗?怎么实现?
2、如果不能实现,那能有其他办法实现吗?高人指点下,感激不尽。
<div><iframe src="b.aspx"></iframe></div>b.aspx的html:
<form id="form1" runat="server">
<asp:Panel ID="Panel1" runat="server" HorizontalAlign="Left"
Style="text-align:left; OVERFLOW-Y: auto;left: 0px; position: relative; top: 0px; SCROLLBAR-SHADOW-COLOR: #ecf2f9; SCROLLBAR-DARKSHADOW-COLOR: #99ccff; SCROLLBAR-FACE-COLOR: #ecf2f9; border-width:1px">
<asp:DataList ID="DLisselect" runat="server" Width="100%" OnItemDataBound="DLisselect_ItemDataBound" RepeatColumns="2" RepeatDirection="Horizontal">
<HeaderTemplate>
<table border="0" cellpadding="0" cellspacing="0" width="100%"
style="background-color:#C5D4F1;text-align:left; border:solid 1px #C5D4F1; padding:2px 2px 0px 2px; font-size:12px;">
<tr style="background-color:#f9f9f9; height:18px">
<td align="center" style="width:100px">序号</td>
<td align="left" style="width:150px">列名</td>
<td align="center">选择</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color:#ffffff;">
<td align="center" style="width:100px"><asp:Label ID="LBcolid" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"orderid") %>'></asp:Label></td>
<td align="left" style="width:150px"><%#DataBinder.Eval(Container.DataItem,"colalias") %></td>
<td align="center"><asp:CheckBox ID="CBisselect" runat="server"/></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr style="background-color:#ffffff;">
<td style="width:100px"></td>
<td style="width:150px"></td>
<td></td>
</tr>
</table>
</FooterTemplate>
</asp:DataList>
</asp:Panel>
<div style="margin-top:10px;">
<asp:Button ID="BtnSave" runat="server" Text="保存条件" OnClick="BtnSave_Click" />
</div>
</form>
b.aspx.cs的codebehind:
单击“保存条件”button执行的事件:
protected void BtnSave_Click(object sender, EventArgs e)
{
CheckBox cbselect = null;
for (int i = 0; i < this.DLisselect.Items.Count; i++)
{
cbselect = this.DLisselect.Items[i].FindControl("CBisselect") as CheckBox;
if (cbselect != null && cbselect.Checked == true)
dtColumn.Rows[i]["isselect"] = true;
else
dtColumn.Rows[i]["isselect"] = false;
}
dtColumn = XQuery.SetOrderID(dtColumn);
if ((!string.IsNullOrEmpty(Login_id)) && (!string.IsNullOrEmpty(Query_no)))
bllxq.BuildQueryPersonal(dtColumn, Login_id, Query_no);
}
问题描述:我想在是想的效果是:我想在a.aspx里面设置一个button来激发和b.aspx里面的"保存条件"button一样的效果。
1、这种效果可以实现吗?怎么实现?
2、如果不能实现,那能有其他办法实现吗?高人指点下,感激不尽。
<input type="button" id="btn1" onclick="javascript:iframe1.src='b.aspx?save=1';">
b.aspx.cs代码:void page_load()
{
if(!IsPostBack)
{
if(Request.QureyString["save"]!=null)
DoSave();
}
}
private void DoSave()
{
CheckBox cbselect = null;
for (int i = 0; i < this.DLisselect.Items.Count; i++)
{
cbselect = this.DLisselect.Items[i].FindControl("CBisselect") as CheckBox;
if (cbselect != null && cbselect.Checked == true)
dtColumn.Rows[i]["isselect"] = true;
else
dtColumn.Rows[i]["isselect"] = false;
}
dtColumn = XQuery.SetOrderID(dtColumn);
if ((!string.IsNullOrEmpty(Login_id)) && (!string.IsNullOrEmpty(Query_no)))
bllxq.BuildQueryPersonal(dtColumn, Login_id, Query_no); }
var win = frame.contentWindow;//frame window对象
var doc = win.document //document对象
var buid= doc.getElementByid("buttonid")//button
buid.click();
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function clickb()
{
window.frames["iframe_ID"].document.getElementById("BtnSave").click();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div> <iframe id="iframe_ID" src="b.aspx"> </iframe> </div>
</div>
<input id="Button1" type="button" onclick="clickb()" value="button" />
</form>
</body>
</html>
iframe 父窗口和子窗口的调用方法2006-11-28 15:15父窗口调用子窗口
iframe_ID.iframe_document_object.object_attribute = attribute_value
例子
onClick="iframe_text.myH1.innerText='http://www.pint.com';"
子窗口调用父窗口
parent.parent_document_object.object_attribute = attribute_value
例子
onclick="parent.myH1.innerText='http://www.pint.com';" 上面在IE下没有问题,但在firefox下不正常。在firefox下,应该是
父窗口调用子窗口
window.frames["iframe_ID"].document.getElementById("iframe_document_object").object_attribute = attribute_value
例子
window.frames["iframe_text"].document.getElementById("myH1").innerHTML= "http://www.pint.com";
子窗口调用父窗口
parent.document.getElementById("parent_document_object").object_attribute = attribute_value
例子
parent.document.getElementById("myH1").innerHTML = "http://www.adsf.com"; test.htm里面firefox下访问iframe 必须用name,不能用id
所以要改为name="iframe_test" 完整的例子
test.htm<HTML>
<HEAD>
<TITLE> Test Page </TITLE>
<script src="prototype-1.4.0.js"></script>
<script language="javascript">
function show(){
window.frames["iframe_text"].document.getElementById("myH1").innerHTML
= "http://www.pint.com"; }
</script>
</HEAD>
<BODY>
<iframe height="350" width="600" src="iframe_text.htm"
name="iframe_text"></iframe>
<form action="" method="post">
<input name="haha" id="haha" type="text" maxlength="30" value="haha"
/><br />
<textarea cols="50" rows="5" id="getAttributeMethod"></textarea>
<input type="button" onClick="show();" value="提交"/>
</form>
<h1 id="myH1">d</h1>
</BODY>
</HTML> frame_test.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript">
function show(){
parent.document.getElementById("myH1").innerHTML =
"http://www.adsf.com"; } </script>
<body>
<h1 id="myH1">ha</h1>
<form action="" method="post">
<input name="abc" id="abc" type="text" maxlength="30" value="abc" /><br
/>
<textarea cols="50" rows="10" id="text"></textarea> <br />
<input type="button" value="提交" onclick="show();"/>
</form>
</body>
</html>
这样写有错误,经过测试:window.frames["iframe_ID"].document 这里是对的,可以取到对象,
这里就取不到了: window.frames["iframe_ID"].document.getElementById("BtnSave")有写错了吗?
没错,我自己写错了ID,IE下是对可以,在firefox下就不管用了
比较好的方案。当通过 document.getElementById("iframeID") 获得iframe对象(ifr)时
可通过 该对象的 ifr.contentWindow 属性 获得iframe对象的document。
,在 document对象中获得按钮对象,之后直接调用该按扭的click 。