.ascx
<asp:TextBox ID="tbEntName" runat="server" Width="70px"></asp:TextBox>
<br />
<asp:TextBox ID="tbPassword" runat="server" Width="70px" TextMode="Password"></asp:TextBox>
<br />
<asp:TextBox ID="tbPassword" runat="server" Width="70px" TextMode="Password"></asp:TextBox>
.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="4.aspx.cs" Inherits="_4" %>
<%@ Register Src="EntLogin.ascx" TagName="EntLogin" TagPrefix="uc1" %>
<!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 runat="server">
<title>无标题页</title>
<script type="text/javascript">
function CheckData()
{
if(document.getElementById("<%=EntLogin1.FindControl("tbEntName").ClientID %>").value == "")
{
alert("名称不能为空!");
return false;
}
if(document.getElementById("<%=EntLogin1.FindControl("tbPassword").ClientID %>").value == "")
{
alert("密码不能为空!");
return false;
}
return true;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc1:EntLogin ID="EntLogin1" runat="server" />
<asp:Button ID="btnTest" runat="server" OnClientClick="return CheckData()" Text="测试" />
</div>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml ">
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function CheckData()
{
if(document.getElementById("<%=EntLogin1.FindControl("tbEntName").ClientID %>").value == "")
{
alert("名称不能为空!");
return false;
}
if(document.getElementById("<%=EntLogin1.FindControl("tbPassword").ClientID %>").value == "")
{
alert("密码不能为空!");
return false;
}
return true;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc1:EntLogin ID="EntLogin1" runat="server" />
<asp:Button ID="btnTest" runat="server" OnClientClick="return CheckData()" Text="测试" />
</div>
</form>
</body>
</html>
========================================
打开新窗口传值回原窗口
原窗口1.html:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function OpenNewDialog(){
window.open('2.html','newwindow','width=400,height=300');
}
</script>
</head>
<body>
<input type="text" id="txt1" />
<input type="button" value="打开新窗口" onclick="OpenNewDialog()"/>
</body>
</html>
<head>
<script type="text/javascript">
function OpenNewDialog(){
window.open('2.html','newwindow','width=400,height=300');
}
</script>
</head>
<body>
<input type="text" id="txt1" />
<input type="button" value="打开新窗口" onclick="OpenNewDialog()"/>
</body>
</html>
新窗口2.html:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function GetVal(){
var txt1 = window.opener.document.getElementById('txt1');
var txt2 = document.getElementById('txt2');
txt1.value = txt2.value;
window.close();
}
</script>
</head>
<body>
<input type="text" id="txt2" />
<input type="button" value="传值" onclick="GetVal()"/>
</body>
</html>
<head>
<script type="text/javascript">
function GetVal(){
var txt1 = window.opener.document.getElementById('txt1');
var txt2 = document.getElementById('txt2');
txt1.value = txt2.value;
window.close();
}
</script>
</head>
<body>
<input type="text" id="txt2" />
<input type="button" value="传值" onclick="GetVal()"/>
</body>
</html>