您的位置:首页 > 其它

在form上设定了defaultbutton属性之后,切换提交按钮的解决办法

2008-04-04 11:05 507 查看
通常我们有些页面需要设置默认提交按钮。也可能碰到如下情况:在搜索框中输入搜索内容后,按回车搜索,但由于页面设置了默认按钮,而且默认按钮不是搜索按钮,此时使用如下脚本通常都会失败:

function textBoxOnKeyDown(event)

function textBoxOnKeyDown(event)

而我测试能工作的脚本如下:
function textBoxOnKeyDown(event)

<!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>

</head>

<body>

<form id="form1" runat="server" defaultbutton="Button1">

<div>

<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

<asp:TextBox ID="TextBox1" runat="server" onkeydown='textBoxOnKeyDown(event)'></asp:TextBox>

<asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" />

</div>

</form>

</body>

</html>

后台代码:
using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

namespace WebApplication5
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐