欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

asp.net中綁定TextBox回車事件的解決方法

 更新時間:2011年07月15日 17:26:50   作者:  
asp.net中綁定TextBox回車事件的解決方法,需要的朋友可以參考下。
1.將頁面上的回車事件都綁定到按鈕上
復(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

相關(guān)文章

最新評論