asp.net中綁定TextBox回車事件的解決方法
更新時間:2011年07月15日 17:26:50 作者:
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事件中設(shè)定按鈕客戶端事件
protected override void OnPreRender(EventArgs e)
{
txtSearch.Attributes.Add("onkeypress", "EnterTextBox(event);")
}
大功告成了。
參考文章:
http://www.dhdzp.com/article/27713.htm
原文參考:
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>
在對應(yīng)的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回車,調(diào)用btnQuery_Click
復(fù)制代碼 代碼如下:
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事件中設(shè)定按鈕客戶端事件
復(fù)制代碼 代碼如下:
protected override void OnPreRender(EventArgs e)
{
txtSearch.Attributes.Add("onkeypress", "EnterTextBox(event);")
}
大功告成了。
參考文章:
http://www.dhdzp.com/article/27713.htm
原文參考:
1.將頁面上所有回車事件都綁定到一個按鈕上
復(fù)制代碼 代碼如下:
<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
復(fù)制代碼 代碼如下:
<HEAD>
<script language="javascript">
function EnterTextBox(button)
{
if(event.keyCode == 13)
{
event.keyCode = 9;
event.returnValue = false;
document.all[button].click();
}
}
</script>
</HEAD>
在對應(yīng)的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代碼:
復(fù)制代碼 代碼如下:
<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回車,調(diào)用btnQuery_Click
您可能感興趣的文章:
- asp.net gridview代碼綁定
- asp.net ListView 數(shù)據(jù)綁定
- asp.net中將數(shù)據(jù)庫綁定到DataList控件的實現(xiàn)方法與實例代碼
- asp.net中ListBox 綁定多個選項為選中及刪除實現(xiàn)方法
- ASP.NET中ListView(列表視圖)的使用前臺綁定附源碼
- asp.net數(shù)據(jù)綁定DataBind使用方法
- asp.net讀取excel中的數(shù)據(jù)并綁定在gridview
- Asp.net中的數(shù)據(jù)綁定Eval和Bind應(yīng)用示例
- ASP.NET MVC數(shù)組模型綁定詳解
相關(guān)文章
Asp.Net防止刷新重復(fù)提交數(shù)據(jù)的辦法
最近在用Asp.Net編寫點東西時遇到個問題:即用戶在提交表單后按刷新就會重復(fù)提交數(shù)據(jù),即所謂的“刷新重復(fù)提交”的問題。2013-03-03
Extjs4.1.x 框架搭建 采用Application動態(tài)按需加載MVC各模塊完美實現(xiàn)
中午的時候發(fā)了第一篇 Extjs4.1.x 框架搭建 采用Application動態(tài)按需加載MVC各模塊,發(fā)現(xiàn)實現(xiàn)上還是有問題,本文將提供詳細(xì)的完美方案2012-11-11

