
方法一:
<asp:Panel ID="panSearch" runat="server" DefaultButton="SearchBtn">
<asp:TextBox ID="KeywordsTextField" runat="server" AutoCompleteType="Search"></asp:TextBox>
<asp:ImageButton ID="SearchBtn" runat="server" ImageUrl="~/images/search_btn.gif?http://www.xvna.com" OnClick="BtnToSearch" ImageAlign="Middle" />
<br />
</asp:Panel>
将TextBox和你要关联的Button放在同一个panel里面,用Panel控件的DefaultButton="SearchBtn"属性来指定要执行那个按钮事件。Panel会生成一个div。
方法二:
view sourceprint?
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function keyDown()
{
if(event.keyCode==13)
{
document.getElementById("Button1").click();
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="KeywordsTextField" runat="server" AutoCompleteType="Search"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click1" />
<br />
</form>
</body>
</html>
因为服务器控件最终生成的还是html。所以虽然textbox里面没有onkeydown这个属性。