在Asp.net网页上工作。我有一个用户控件,需要在我的页面上多次使用此控件。图像显示此javascript错误。如何在同一页面中多次使用用户控件。
页面语法:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication4.WebForm1" %>
<%@ Register src="ucTest.ascx" tagname="ucTest" tagprefix="uc1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<uc1:ucTest ID="ucTest1" runat="server" />
<uc1:ucTest ID="ucTest2" runat="server" />
<uc1:ucTest ID="ucTest3" runat="server" />
</form>
</body>
</html>
用户控制语法:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ucTest.ascx.cs" Inherits="WebApplication4.ucTest" %>
<asp:TextBox runat="server" ID="txtFrom" />
<asp:TextBox ID="txtTo" runat="server"></asp:TextBox>
<script type="text/javascript">
var txtFrom = document.getElementById("<%= txtFrom.ClientID %>");
var txtTo = document.getElementById("<%= txtTo.ClientID %>");
txtFrom.onblur = function () {
debugger;
txtTo.value = txtFrom.value;
alert(txtTo);
}
</script>
javascript错误: