设三个页面:Father.aspx SubOpen.aspx SubModalDialog.aspx
在Father.aspx中:
<asp:Button ID="Button1" runat="server" Text="一般窗口" OnClientClick="openwin() />
<asp:Button ID="Button2" runat="server" Text="模态窗口" OnClientClick="openmodalwin()"/>
<asp:TextBox ID="backvalue" runat="server"></asp:TextBox>
写JAVASCRIPT函数:
<script language="javascript">
function openwin()
{
var
childwin=window.open ("Sub.aspx","1","height=400px,width=400px,top=400px,left=400px");
childwin.Fvalue.value="一般窗口";
}
function openmodalwin()
{
window.param="模态窗口";
var str=window.showModalDialog("Sub.aspx",window,"dialogtop:200px;
dialogleft:300px;status:no;help:no");
if(str!=null)
{
document.getElementById("backvalue").value=str;
}
}
</script>
在SubOpen.aspx中:
function backtowina()
{
window.opener.document.getElementById("backvalue").value=document.getElementById("Svalue").value;
}
传来的值: <asp:TextBox ID="Fvalue" runat="server"></asp:TextBox>
传回去的值: <asp:TextBox ID="Svalue" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="设定主页面值" OnClick="backtowina()" />
在SubModalDialog.aspx中:
window.document.getElementById("Fvalue").value=window.dialogArguments.param;
var parentwin=window.dialogArguments;
function backtowinb()
{
parentwin.document.getElementById("backvalue").value=document.getElementById
("Svalue").value;
}
传来的值: <asp:TextBox ID="Fvalue" runat="server"></asp:TextBox>
传回去的值: <asp:TextBox ID="Svalue" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="设定主页面值" OnClick="backtowinb()" />
最后在加一个小功能:鼠标经过GridView时行背景发生变化
在GridView1的RowDataBound事件里加以下代码就可以了
if (e.Row.RowIndex > -1 && e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowType != DataControlRowType.Header)//鼠标在表头背景不变
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#ccccff'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#ffffff'");
}
}