用户控件的代码
<asp:TextBox ID="TextBox1" runat="server" onfocus="getfocus()" onblur="lostfocus()" >
</asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="..." />
<asp:TextBox ID="txtValue" runat="server"></asp:TextBox>
<asp:TextBox ID="txtText" runat="server" ></asp:TextBox> <script type="text/javascript" language="javascript">
function getfocus()
{
alert("get me");//这里如何换成,当用户控件中TextBox1得焦点后,取其txtValue的值?
}
function lostfocus()
{
alert("lost me");//这里如何换成,当用户控件中TextBox1失焦点后,取其txtText的值?
//document.form1.TextBox1.value=document.form1.TextBox2.value;
}
//加功能:当用户控件的TextBox1中在录入时,其txtValue的内容随着变
//原来想在WebUserControl1.ascx的textbox1的textchange事件中加了,但加了不起作用???
//以上这些想要实现这类功能,就只能放在 脚本里实现,不后放在后台代码吗?
</script>功能说明:
TextBox1用来显示txtValue或txtText,txtValue放诸如编号之类,txtText放诸如名称之类。
TextBox1得焦点显示 编号,失焦点显示名称。
<asp:TextBox ID="TextBox1" runat="server" onfocus="getfocus()" onblur="lostfocus()" >
</asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="..." />
<asp:TextBox ID="txtValue" runat="server"></asp:TextBox>
<asp:TextBox ID="txtText" runat="server" ></asp:TextBox> <script type="text/javascript" language="javascript">
function getfocus()
{
alert("get me");//这里如何换成,当用户控件中TextBox1得焦点后,取其txtValue的值?
}
function lostfocus()
{
alert("lost me");//这里如何换成,当用户控件中TextBox1失焦点后,取其txtText的值?
//document.form1.TextBox1.value=document.form1.TextBox2.value;
}
//加功能:当用户控件的TextBox1中在录入时,其txtValue的内容随着变
//原来想在WebUserControl1.ascx的textbox1的textchange事件中加了,但加了不起作用???
//以上这些想要实现这类功能,就只能放在 脚本里实现,不后放在后台代码吗?
</script>功能说明:
TextBox1用来显示txtValue或txtText,txtValue放诸如编号之类,txtText放诸如名称之类。
TextBox1得焦点显示 编号,失焦点显示名称。
document.getElementById('<%= this.TextBox1.ClientID %>').value=document.getElementById('<%= this.txtValue.ClientID %>').value;是不是前面还得加_或$什么的,看网上这么说的,具体不知怎么来写。