silanos_1

Analytics

ad silanors2

2017年2月14日 星期二

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


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



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

沒有留言:

as silanors3

熱門文章

bloggerads