Analytics

2017年2月14日 星期二

[Javascript]如何 使用顯示訊息後focus到TextBox (How to use the display message after the focus to the TextBox)


問題
如何 使用顯示訊息後focus到TextBox



解決方法
.aspx
  1. <script type="text/javascript">
  2.  
  3. function alertAfterFocus(message, objID) {
  4.  
  5. alert(message);
  6.  
  7. window.setTimeout(function() {
  8.  
  9. document.getElementById(objID).focus();
  10.  
  11. }, 0);
  12.  
  13. }
  14.  
  15. </script>
.cs
  1. private void ShowMessage(string msg, string objID)
  2.  
  3. {
  4.  
  5.     msg = msg.Replace("\n", "\\n");
  6.  
  7.     msg = msg.Replace("\'", string.Empty);
  8.  
  9.     string message = string.Format("alertAfterFocus('{0}','{1}');", msg, objID);
  10.  
  11.     ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alert" + System.Guid.NewGuid().ToString(), message, true);
  12.  
  13. }
  14.  
how to use
  1. ShowMessage("xxx must keyin!!", this.textBox1.ClientID);

沒有留言:

熱門文章