public static void MakeDefault(System.Web.UI.Page oPage, TextBox oTxt, ImageButton
oBtn)
{
StringBuilder sb = new StringBuilder();
sb.Append("<SCRIPT language='javascript'>");
sb.Append("function fnTrapKD(btn){");
sb.Append(" if (document.all){");
sb.Append(" if (event.keyCode == 13)");
sb.Append(" { ");
sb.Append(" event.returnValue=false;");
sb.Append(" event.cancel = true;");
sb.Append(" btn.click();");
sb.Append(" } ");
sb.Append(" } ");
sb.Append("}");
sb.Append("</SCRIPT>");
oTxt.Attributes.Add("onkeydown", "fnTrapKD(document.all."
+ oBtn.ClientID + ")");
oPage.RegisterStartupScript("ForceDefaultToScript", sb.ToString());
}
Call this function, eg: MakeDefault(Page, TextBox1, Button1)
Comments
Post a Comment