ASP.NET中怎么把Button的Accesskey设成回车键?
发布网友
发布时间:2022-04-10 13:24
我来回答
共1个回答
热心网友
时间:2022-04-10 14:53
设置按钮的UseSubmitBehavior属性为True
服务器解析后的html就为submit按钮
如果是ImageButton的话就用javascript控制了
//定义设置默认按钮函数
public static void SetDefEnterControl(System.Web.UI.Control Ctrl)
{
Page mPage = Ctrl.Page;
string mScript;
mScript = @"<script language=""javascript""> ";
mScript += "function document.onkeydown() {";
mScript += "var e = event.srcElement; ";
mScript += "var k = event.keyCode; ";
mScript += @"if (k == 13 && e.type != ""textarea"") { ";
mScript += "document.all." + Ctrl.ClientID + ".click(); ";
mScript += "event.cancelBubble = true; ";
mScript += "event.returnValue = false; ";
mScript += "} }</script>";
if (mPage.IsClientScriptBlockRegistered("SetEnterControl") == false)
mPage.RegisterClientScriptBlock("SetEnterControl", mScript);
}
//在pageload()事件中在设置
SetDefEnterControl(ImageButton1);
参考资料:http://www.xuebida.net/a/Network_programming/.Net%20programming/2010/0203/666.html