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.dbjr.com.cn/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.dbjr.com.cn/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控件的實(shí)現(xiàn)方法與實(shí)例代碼
- asp.net中ListBox 綁定多個選項為選中及刪除實(shí)現(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)文章
.net core 讀取本地指定目錄下的文件的實(shí)例代碼
這篇文章主要介紹了.net core 讀取本地指定目錄下的文件的實(shí)例代碼,非常不錯,具有一定的參考借鑒價值 ,需要的朋友可以參考下2018-09-09ASP.NET MVC5網(wǎng)站開發(fā)我的咨詢列表及添加咨詢(十二)
這篇文章主要為大家詳細(xì)介紹了ASP.NET MVC5網(wǎng)站開發(fā)我的咨詢列表及添加咨詢,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2015-09-09asp.net實(shí)現(xiàn)調(diào)用存儲過程并帶返回值的方法
這篇文章主要介紹了asp.net實(shí)現(xiàn)調(diào)用存儲過程并帶返回值的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了asp.net存儲過程調(diào)用的相關(guān)技巧,需要的朋友可以參考下2016-03-03一個簡單的ASP.NET Forms 身份認(rèn)證的實(shí)例方法
當(dāng)訪問默認(rèn)首頁default.aspx時,會自動跳轉(zhuǎn)到login.aspx頁面上請求登錄,隨便輸入用戶名和密碼,點(diǎn)擊“登錄”按鈕,會回到首頁,并顯示當(dāng)前登錄的用戶名。2013-07-07