ASP.net绑定文本框Enter事件到按钮 ASP.NET执行后台执行JS方法

txtAccountBarcode.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + btnSearchN.UniqueID + "').click();return false;}} else {return true}; ")

 

 'To simplify the process to write javascript in vb code
    Public Sub CallJSFunction(ByVal strKey As String, ByVal strJScript As String)
        Me.Page.RegisterStartupScript(strKey, "<script language='javascript'>" + strJScript + "</script>")
    End Sub

    'To Set the focus to the specific control
    Public Sub SetFocus(ByVal strControlID As String)
        CallJSFunction("setFocus", "document.getElementById('" + strControlID + "').focus()")
        'CallJSFunction("setFocus", "document.getElementById('" + strControlID + "').select()")
    End Sub

注:后台执行JS似乎只有在页面提交或刷新时才有作用,直接起效只有使用前台JS实现。

posted @ 2013-08-07 15:30  龍☆  阅读(355)  评论(0编辑  收藏  举报