public static void SetDefEnterControl(System.Web.UI.Control Ctrl)
{
Page mPage = Ctrl.Page;
string mScript;
mScript = @"<script language=""javascript""> ";
mScript = mScript + "function document.onkeydown() {";
mScript = mScript + "var e = event.srcElement; ";
mScript = mScript + "var k = event.keyCode; ";
mScript = mScript + @"if (k == 13 && e.type != ""textarea"") { ";
mScript = mScript + "document.all." + Ctrl.ClientID + ".click(); ";
mScript = mScript + "event.cancelBubble = true; ";
mScript = mScript + "event.returnValue = false; ";
mScript = mScript + "} }</script>";
if (mPage.IsClientScriptBlockRegistered("SetEnterControl") == false)
mPage.RegisterClientScriptBlock("SetEnterControl", mScript);
}
调用的时候可以用
SetDefEnterControl(按钮控件名);
即可
{
Page mPage = Ctrl.Page;
string mScript;
mScript = @"<script language=""javascript""> ";
mScript = mScript + "function document.onkeydown() {";
mScript = mScript + "var e = event.srcElement; ";
mScript = mScript + "var k = event.keyCode; ";
mScript = mScript + @"if (k == 13 && e.type != ""textarea"") { ";
mScript = mScript + "document.all." + Ctrl.ClientID + ".click(); ";
mScript = mScript + "event.cancelBubble = true; ";
mScript = mScript + "event.returnValue = false; ";
mScript = mScript + "} }</script>";
if (mPage.IsClientScriptBlockRegistered("SetEnterControl") == false)
mPage.RegisterClientScriptBlock("SetEnterControl", mScript);
}
调用的时候可以用
SetDefEnterControl(按钮控件名);
即可
作者:管宇
欢迎转载,请标明出处。