发布于 2016-06-17 21:58:19 | 147 次阅读 | 评论: 1 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

ASP.NET

ASP.NET 是.NET FrameWork的一部分,是一项微软公司的技术,是一种使嵌入网页中的脚本可由因特网服务器执行的服务器端脚本技术,它可以在通过HTTP请求文档时再在Web服务器上动态创建它们。 指 Active Server Pages(动态服务器页面) ,运行于 IIS(Internet Information Server 服务,是Windows开发的Web服务器)之中的程序 。


asp.net中绑定TextBox回车事件的解决方法,需要的朋友可以参考下。
1.将页面上的回车事件都绑定到按钮上
 
function EnterTextBox(e) 
{ 
var msie = (document.all) ? true : false; 
var keycode; 
if(!msie) keycode = window.event ? e.keyCode : e.which; 
else keycode = e.keyCode; 
//alert(keycode); 
if(keycode==13 && document.getElementById('<%=this.txtSearch.ClientID%>').value != "") 
{ 
//alert("test"); 
if(msie) 
{ 
e.keyCode = 9; 
e.returnValue = false; 
} 
document.getElementById('<%=this.btnSearch.ClientID%>').click(); 
} 
} 

2. 在OnPreRender事件中设定按钮客户端事件
 
protected override void OnPreRender(EventArgs e) 
{ 
txtSearch.Attributes.Add("onkeypress", "EnterTextBox(event);") 
} 

大功告成了。
参考文章: 
/article/16/0522/224165.html

原文参考:
1.将页面上所有回车事件都绑定到一个按钮上
 
<HEAD> 
<script language="javascript"> 
function EnterTextBox() 
{ 
if(event.keyCode == 13 && document.all["TextBox1"].value != "") 
{ 
event.keyCode = 9; 
event.returnValue = false; 
document.all["Button1"].click(); 
} 
} 
</script> 
</HEAD> 
<body onkeypress="return EnterTextBox()"> 

2.不同的TextBox绑定不同的Button
 
<HEAD> 
<script language="javascript"> 
function EnterTextBox(button) 
{ 
if(event.keyCode == 13) 
{ 
event.keyCode = 9; 
event.returnValue = false; 
document.all[button].click(); 
} 
} 
</script> 
</HEAD> 

在对应的cs文件中
//绑定TextBox回车事件
TextBoxPortOfDestination.Attributes.Add("onkeypress", "EnterTextBox('ButtonChoose')");
TextBoxItemName.Attributes.Add("onkeypress","EnterTextBox('ButtonAdd')");
TextBoxCost_PX.Attributes.Add("onkeypress","EnterTextBox('ButtonAdd')");
TextBoxCost_1X20.Attributes.Add("onkeypress","EnterTextBox('ButtonAdd')");
web代码:

<fieldset> 
<legend id="LegendDetail" [查詢條件]</legend> 
<table> 
<tr><td> 
<asp:TextBox ID="TextBox 1" runat="server"></asp:TextBox></td> 
</tr> 
<tr> 
<td > 
<asp:Button ID="btn" runat="server" OnClick="btnQuery_Click"/></td> 
</tr> 
</table> 
</fieldset> 

是这样的模式。在textbox回车,调用btnQuery_Click

最新网友评论  共有(1)条评论 发布评论 返回顶部
tmtdu 发布于2016-06-27 03:14:37
沙发
支持(0)  反对(0)  回复

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务