aspx的cs文件中注册Javascript
txtPageIndex.Attributes.Add("onFocus", string.Format("{0}.select();", txtPageIndex.ClientID));
txtPageIndexBack.Attributes.Add("onFocus", string.Format("{0}.select();", txtPageIndexBack.ClientID));
btnGO.OnClientClick = string.Format("if(!isNumber({0}.value)) {{ return false; }};", txtPageIndex.ClientID);
btnGoBack.OnClientClick = string.Format("if(!isNumber({0}.value)) {{ return false; }};" , txtPageIndexBack.ClientID);
txtPageIndexBack.Attributes.Add("onFocus", string.Format("{0}.select();", txtPageIndexBack.ClientID));
btnGO.OnClientClick = string.Format("if(!isNumber({0}.value)) {{ return false; }};", txtPageIndex.ClientID);
btnGoBack.OnClientClick = string.Format("if(!isNumber({0}.value)) {{ return false; }};" , txtPageIndexBack.ClientID);
1. btnGO如果有服务器端事件,也有客户端JS事件,为了让JS执行返回失败后不让页面PostBack, 一定要让JS代码返回false.
2. 为了防止控件ID在parse成html页面后有所改变而产生潜在bug,用控件的ClientID作为JS代码中ID。